我试图在this guide之后根据the Heroku docs将基本的Wagtail Django网站(pip install wagtail
)推送到Heroku,我得到了一个非常常见的postgres连接错误(下面)。我可以从仪表板上看到Heroku正在提供实时数据库,我可以使用heroku pq:psql
访问它。
项目在本地运行,也在我运行heroku local
时运行。
我的`project / app / settings / production.py'按建议设置:
import os
env = os.environ.copy()
SECRET_KEY = env['SECRET_KEY']
from __future__ import absolute_import, unicode_literals
from .base import *
DEBUG = False
try:
from .local import *
except ImportError:
pass
# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost')}
print('check')
print(DATABASES)
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Allow all host headers
ALLOWED_HOSTS = ['*']
Procfile
(来自回购根)
web: gunicorn myproj.wsgi:application --log-file -
myproj/wsgi.py
from __future__ import absolute_import, unicode_literals
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproj.settings.dev")
application = get_wsgi_application()
我得到的错误:
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/base.py", line 189, in connect
self.connection = self.get_new_connection(conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/base.py", line 176, in get_new_connection
connection = Database.connect(**conn_params)
File "/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
有人可以帮忙吗?
答案 0 :(得分:2)
您的wsgi文件指向您的开发设置;生产的产品根本没有被使用。
使用setdefault
设置环境变量意味着如果已经设置了现有值,则将优先使用该值。因此,您应该运行heroku config:set DJANGO_SETTINGS_MODULE=myproj.settings.production
来设置该值。