Django Gives Bad Request (400) Upon Rolling to Production

If the code run in development but fails with a Bad Request (400) error when you roll it to production.

And there is no indication of what is wrong in the logs.

Try toggling
DEBUG = True
from
DEBUG = False
in settings.py

Restart the webserver
sudo service httpd restart

And retry reloading the page. If it works then is is possibly an
ALLOWED_HOSTS issue.

Bad Fix (don’t do this)! This can cause security issues later as one should limit to the relevant hosts.
ALLOWED_HOSTS = ['*']

Doesn’t work I have seen this answer several places, it is wrong and doesn’t work with version 1.9.4 of Django. Do NOT attempt to mix the asterisk with the host parts
ALLOWED_HOSTS = ['repasta.com', '*.repasta.com', 'localhost']

Works
ALLOWED_HOSTS = ['repasta.com', '.repasta.com', 'localhost']

Web page now shows correctly. Yay!

George Lee

A full stack engineer who has coded on front end, back end, and mobile and embedded system. Have worked on large scale systems at eBay and agile environments at startups. Specialties: Python, PHP, Objective C, Java, Perl, SQL, Javascript, IOS, Android, Amazon EC2, Linux and Windows.

One thought on “Django Gives Bad Request (400) Upon Rolling to Production

  1. I have been surfing online more than 3 hours today,
    yet I never found any interesting article like yours.
    It is pretty worth enough for me. In my view, if all website owners and bloggers made good content as you did, the net will be much more useful than ever before. http://www.yahoo.net

Leave a Reply

Your email address will not be published. Required fields are marked *