我一直在制作一个 django 应用程序,现在正尝试将它部署到 heroku。
但是,当我继续它时,显示 Server Error (500)
,并且日志显示:2017-05-27T21:00:14.634310+00:00 heroku[router]: at=info method=GET path="/"host=remberit.herokuapp.com request_id=065d27c6-9211-458f-9fc6-bb677d43581e fwd="86.13.204.65"dyno=web.1 connect=0ms service=151ms status=500 bytes=387协议(protocol)=https
这是我的 settings.py(至少是相关部分,但请询问您是否需要其余部分):
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, "staticfiles")
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
import dj_database_url
DATABASES['default'] = dj_database_url.config()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
ALLOWED_HOSTS = ['*']
DEBUG = False
try:
from .local_settings import *
except ImportError:
pass
这是我的 wsgi.py:
import os
from django.core.wsgi import get_wsgi_application
#from whitenoise.django import DjangoWhiteNoise
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'remberit.settings')
django.setup()
application = get_wsgi_application()
#application = DjangoWhiteNoise(application)
这是我的程序文件:
web: gunicorn remberit.wsgi
这是我的 runtime.txt:
python-3.5.2
这是我的要求.txt:
appdirs==1.4.3
dj-database-url==0.4.2
gunicorn==19.7.1
packaging==16.8
pyparsing==2.2.0
six==1.10.0
whitenoise==3.3.0
psycopg2==2.6.2
这是 pip freeze
的输出:
appdirs==1.4.3
dj-database-url==0.4.2
gunicorn==19.7.1
packaging==16.8
pyparsing==2.2.0
six==1.10.0
whitenoise==3.3.0
此外,当我使用 gunicorn remberit.wsgi
或 python manage.py runserver
在本地运行应用程序时它工作正常,只有当我使用 heroku 时它才不起作用.
如果您需要更多信息,请告诉我。
最佳答案
可能会解决您的问题的其他解决方案:从 whitenoise 中注释掉或删除 GzipManifestStaticFilesStorage。由于某种原因,这不能正常工作。
# STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
在 Why would django fail with server 500 only when Debug=False AND db is set to production database on Heroku? 上找到了这个解决方案
关于python - 将 Django 部署到 Heroku - 服务器错误 (500),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44221653/