Skip to main content
 首页 » 编程设计

python之Heroku 上的错误请求 400 Django 应用程序

2024年12月31日22qq78292959

伙计们,在 heroku 中部署我的 django 应用程序时出现问题 这是我的 procfile

web:gunicorn drf.wsgi:application --log-file - 
web: python manage.py runserver 0.0.0.0:$PORT 

wsgi.py

import os 
from whitenoise.django import DjangoWhiteNoise 
 
from django.core.wsgi import get_wsgi_application 
 
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "drf.settings") 
 
application = get_wsgi_application() 
application = DjangoWhiteNoise(application) 

也添加了允许的主机

  ALLOWED_HOSTS = ['mxiondrf.herokuapp.com'] 

这是我的日志

18-07-23T23:34:50.814903+00:00 heroku[router]: at=info method=GET path="/" host=mxiondrf.herokuapp.com request_id=f4f07d1 
b-be4a-4f62-85e0-6701c420da1c fwd="103.49.121.34" dyno=web.1 connect=0ms service=93ms status=400 bytes=154 protocol=https 
2018-07-23T23:34:51.408577+00:00 app[web.1]: [23/Jul/2018 23:34:51] "GET /favicon.ico HTTP/1.1" 400 26 
2018-07-23T23:34:51.410953+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=mxiondrf.herokuapp.com request 
_id=951b1ad8-0716-43c0-b21e-a8390ff59e63 fwd="103.49.121.34" dyno=web.1 connect=0ms service=79ms status=400 bytes=154 proto 
col=https 
2018-07-23T23:34:54.506740+00:00 heroku[router]: at=info method=GET path="/" host=mxiondrf.herokuapp.com request_id=581d35d 
6-bdf3-49f9-9c4f-a74d6c39da08 fwd="103.49.121.34" dyno=web.1 connect=1ms service=60ms status=400 bytes=154 protocol=https 
2018-07-23T23:34:54.506394+00:00 app[web.1]: [23/Jul/2018 23:34:54] "GET / HTTP/1.1" 400 26 
2018-07-23T23:34:55.006560+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=mxiondrf.herokuapp.com request 
_id=c0c33673-f212-4679-ada8-7e7719e283eb fwd="103.49.121.34" dyno=web.1 connect=0ms service=124ms status=400 bytes=154 prot 
ocol=https 
2018-07-23T23:34:55.004234+00:00 app[web.1]: [23/Jul/2018 23:34:55] "GET /favicon.ico HTTP/1.1" 400 26 

感谢任何形式的帮助

请您参考如下方法:

在 Procfile 中您应该只有一个 web 条目

它应该是

web: gunicorn mysite.wsgi