我正在尝试将我的django应用程序部署到heroku上。如果在Procfile:web: python manage.py runserver
中,它的成功完全正常。
将设置更新为本地和制作后,在production.py DEBUG=False
中导致我的django应用程序出现错误500 page
。
但是,如果我导航到appname.herokuapp.com/admin
,css文件已损坏,但我仍然可以访问应用管理页面。看看我的项目文件树:
项目中的设置文件夹
settings
│ base.py
│ local.py
│ production.py
│ __init__.py
│
production.py
from django.core.exceptions import ImproperlyConfigured
import logging
try:
from .base import *
import dj_database_url
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# Update database configuration with $DATABASE_URL.
ALLOWED_HOSTS = ['www.appname.herokuapp.com', 'appname.herokuapp.com']
log = logging.getLogger(__name__)
log.info(msg='Setting is from production.py')
DEBUG = False
ADMIN = ('admin','xxx@gmail.com' )
# Get production configuration
SECRET_KEY = os.environ.get('SECRET_KEY')
DATABASES['default'] = dj_database_url.config()
except (ImportError, ImproperlyConfigured) as e:
print('Error occurred while importing the base.py in production.py')
Procfile
web: gunicorn project.wsgi
该应用已成功部署,我可以浏览管理页面,但不能浏览应用程序
经过研究,我认为这可能是ALLOWED_HOST=[]
的问题,但如果没有ALLOWED_HOST=['appname.herokuapp.com']
则无法获取[*]
。
heroku日志
2017-01-18T14:45:44.802163+00:00 heroku[web.1]: Restarting
2017-01-18T14:45:44.804042+00:00 heroku[web.1]: State changed from up to starting
2017-01-18T14:45:45.669518+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2017-01-18T14:45:45.687608+00:00 app[web.1]: [2017-01-18 14:45:45 +0000] [9] [INFO] Worker exiting (pid: 9)
2017-01-18T14:45:45.688006+00:00 app[web.1]: [2017-01-18 14:45:45 +0000] [4] [INFO] Handling signal: term
2017-01-18T14:45:45.688703+00:00 app[web.1]: [2017-01-18 14:45:45 +0000] [8] [INFO] Worker exiting (pid: 8)
2017-01-18T14:45:45.888782+00:00 app[web.1]: [2017-01-18 14:45:45 +0000] [4] [INFO] Shutting down: Master
2017-01-18T14:45:46.119617+00:00 heroku[web.1]: Process exited with status 0
2017-01-18T14:45:50.356542+00:00 heroku[web.1]: Starting process with command `gunicorn vnc.wsgi --log-file=-`
2017-01-18T14:45:52.894929+00:00 app[web.1]: [2017-01-18 14:45:52 +0000] [4] [INFO] Starting gunicorn 19.6.0
2017-01-18T14:45:52.895493+00:00 app[web.1]: [2017-01-18 14:45:52 +0000] [4] [INFO] Listening at: http://0.0.0.0:57728 (4)
2017-01-18T14:45:52.895580+00:00 app[web.1]: [2017-01-18 14:45:52 +0000] [4] [INFO] Using worker: sync
2017-01-18T14:45:52.898787+00:00 app[web.1]: [2017-01-18 14:45:52 +0000] [8] [INFO] Booting worker with pid: 8
2017-01-18T14:45:52.993553+00:00 app[web.1]: [2017-01-18 14:45:52 +0000] [9] [INFO] Booting worker with pid: 9
2017-01-18T14:45:54.055081+00:00 heroku[web.1]: State changed from starting to up
2017-01-18T14:46:22.582563+00:00 heroku[router]: at=info method=GET path="/" ost=.herokuapp.com request_id=196fad42-b37e-4c02-a8e4-06ff5947b77d fwd="208.23.227.53" dyno=web.1 connect=0ms service=272ms status=500 bytes=384
2017-01-18T14:46:24.750287+00:00 heroku[router]: at=info method=GET path="/" host=.herokuapp.com request_id=060c7e6e-fa6c-46be-823d-3993a43fae00 fwd="208.23.227.53" dyno=web.1 connect=6ms service=75ms status=500 bytes=384
2017-01-18T14:46:25.809511+00:00 heroku[router]: at=info method=GET path="/" host=.herokuapp.com request_id=9bc94eb6-d864-4d77-8c02-3d136fdf48dd fwd="208.23.227.53" dyno=web.1 connect=0ms service=76ms status=500 bytes=384
2017-01-18T14:46:27.536300+00:00 heroku[router]: at=info method=GET path="/" host=.herokuapp.com request_id=7dca33df-c100-4a33-8f51-b3e0b9c0f8d5 fwd="208.23.227.53" dyno=web.1 connect=0ms service=108ms status=500 bytes=384
2017-01-18T14:47:56.441121+00:00 heroku[router]: at=info method=GET path="/" host=.herokuapp.com request_id=a5823328-a871-4d1f-80ea-b75b7e288dbe fwd="208.23.227.53" dyno=web.1 connect=0ms service=57ms status=500 bytes=384
2017-01-18T14:47:59.133729+00:00 heroku[router]: at=info method=GET path="/admin/" host=.herokuapp.com request_id=5d482ad9-5485-4a15-94bc-3864f104257d fwd="208.23.227.53" dyno=web.1 connec t=0ms service=227ms status=200 bytes=7819
2017-01-18T14:47:59.232750+00:00 heroku[router]: at=info method=GET path="/static/admin/css/dashboard.4898e2e9983d.css" host=.herokuapp.com request_id=b64f6087-7e64-4f76-883b-b5328ee591ce fwd="208.23.227.53" dyno=web.1 connect=1ms service=4ms status=404 bytes=358
2017-01-18T14:47:59.214759+00:00 heroku[router]: at=info method=GET path="/static/admin/css/base.ba3dc2f88fc5.css" host=.herokuapp.com request_id=8474679b-ef79-4753-9afc-31bef9f5b179 fwd=" 208.23.227.53" dyno=web.1 connect=0ms service=4ms status=404 bytes=358
答案 0 :(得分:1)
好的,最后经过这个问题的许多帖子后,罪魁祸首。
在添加项目最终运行的所有css文件后,几乎没有正确添加的css图像。
对于使用whitenoise进行部署的所有人来说,尝试从cli本地运行heroku应用程序。尝试运行promo10,yesss,promo111,zz12
并且如果有任何其他命令可能在heroku上使用。
添加collectstatic
和
ADMIN
如果任何一方失败,他们会派上用场。