Debugging Apache/Django/WSGI Bad Request (400) Error

£可爱£侵袭症+ 提交于 2019-11-28 04:16:55

Add the ALLOWED_HOSTS setting to your settings.py like so...

ALLOWED_HOSTS = [
    '.example.com', # Allow domain and subdomains
    '.example.com.', # Also allow FQDN and subdomains
]

I had this same problem and found the answer here in the docs

update: django 1.6 docs are no longer online, I updated the link to go to the django 1.7 docs for ALLOWED_HOSTS setting.

If you've definitely set ALOWED_HOSTS - make sure your hostname doesn't contain underscores. It's technically illegal.

I had to print out various functions and it boiled down to this regex failing to detect a domain in django.http

host_validation_re = re.compile(r"^([a-z0-9.-]+|\[[a-f0-9]*:[a-f0-9:]+\])(:\d+)?$")

And indeed, my domain had an underscore in it.

user3770635

This is not a solution, but for debugging purposes you might set the ALLOWED_HOSTS setting in your settings.py like this

ALLOWED_HOSTS = ['*']

It should definitely work. If not, at least you will know the problem isn't Django denying access to the given url.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!