Heroku Django remote:服务器是否在本地运行并接受该套接字上的连接?Heroku 姜戈

Heroku Django remote: Is the server running locally and accepting connections on that socket? heroku django

提问人:Joe Jay 提问时间:8/21/2023 更新时间:8/21/2023 访问量:23

问:

所以我一直在尝试在 heroku 上运行我的 django 应用程序,它在本地与数据库配合良好,所以这是我 base.py 中的一些问题,我还没有能够识别。如果有人遇到过类似的问题并有解决方案,我环顾四周一段时间没有提示:(

错误信息: remote:正在验证部署...做。 remote:正在运行发布命令... 远程: remote:回溯(最近一次调用最后一次): remote:文件“/app/.heroku/python/lib/python3.10/site-packages/django/db/backends/base/base.py”,第 289 行,ensure_connection 远程:self.connect() 远程:文件“/app/.heroku/python/lib/python3.10/site-packages/django/utils/asyncio.py”,第 26 行,在内部 remote: return func(*args, **kwargs) 远程:文件“/app/.heroku/python/lib/python3.10/site-packages/django/db/backends/base/base.py”,第 270 行,在连接中 远程:self.connection = self.get_new_connection(conn_params) 远程:文件“/app/.heroku/python/lib/python3.10/site-packages/django/utils/asyncio.py”,第 26 行,在内部 remote: return func(*args, **kwargs) remote:文件“/app/.heroku/python/lib/python3.10/site-packages/django/db/backends/postgresql/base.py”,第 275 行,get_new_connection 远程:连接 = 自身。数据库连接 (**conn_params) 远程:文件“/app/.heroku/python/lib/python3.10/site-packages/psycopg2/init.py”,第 122 行,在连接中 远程:conn = _connect(dsn, connection_factory=connection_factory, **kwasync) 远程:psycopg2。OperationalError:连接到套接字“/var/run/postgresql/.s.PGSQL.5432”上的服务器失败:没有这样的文件或目录 remote:服务器是否在本地运行并接受该套接字上的连接?

base.py

import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get("APP_SECRET")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django.contrib.sites",
    # Apps
    "profiles",
    "posts",
    # Django All-Auth
    "allauth",
    "allauth.account",
    "allauth.socialaccount",
]

SITE_ID = 1

LOGIN_REDIRECT_URL = "/posts"

ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_UNIQUE = True


MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    'whitenoise.middleware.WhiteNoiseMiddleware',
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "social.urls"

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [BASE_DIR / "templates"],
        "APP_DIRS": True,
        "OPTIONS": {
            "context_processors": [
                "django.template.context_processors.debug",
                "django.template.context_processors.request",
                "django.contrib.auth.context_processors.auth",
                "django.contrib.messages.context_processors.messages",
                "profiles.context_processors.profile_pic",
                "profiles.context_processors.invitations_received_count",
            ],
        },
    },
]

AUTHENTICATION_BACKENDS = [
    "django.contrib.auth.backends.ModelBackend",
    "allauth.account.auth_backends.AuthenticationBackend",
]

WSGI_APPLICATION = "social.wsgi.application"


# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        "NAME": os.environ.get("DB_NAME"),
        "USER": os.environ.get("DB_USER"),
        "PASSWORD": os.environ.get("DB_PASSWORD"),
        "HOST": os.environ.get("DB_HOST"),
        "PORT": os.environ.get("DB_PORT"),
    },
}


# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
    },
    {
        "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
    },
]


# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/

STATIC_URL = "static/"

STATICFILES_DIRS = [
    BASE_DIR / STATIC_URL,
]

STATIC_ROOT = BASE_DIR / "static/" / "static_root"

# Media files

MEDIA_URL = "media/"

MEDIA_ROOT = BASE_DIR / MEDIA_URL

# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"`

Django 虚拟主机 Heroku-Postgres

评论


答: 暂无答案