Django 400 bad request

The HyperText Transfer Protocol (HTTP) 400 Bad Request response status code indicates that the server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).

If you are getting a 400 Bad Request while accessing your own Django application, then read on as the solution is here.

This error in Django indicates that the server was unable to process the request sent by the client due to invalid syntax.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to fix Django related errors.

In this context, we shall look into how to fix this error.

Tips to fix Django 400 bad request error?

You try the following tips to resolve 400 bad request error in Django.

1. Correct the Invalid syntax

Recently, one of our customers approached telling us that the Django server was running fine with DEBUG = True

But, when the DEBUG is set to False in the settings file, then the server will stop and throw the below error in the command prompt:

CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.

After changing ALLOWED_HOSTS to,["",] in the browser, the customer received the below error:

Bad Request (400)

Our Support Experts started troubleshooting the error by setting the ALLOWED_HOSTS list to fully qualified hostnames.

We didn't set the URL in it.  And, omitted the port and the protocol:

ALLOWED_HOSTS = ['', 'localhost']

Since our customer was using, we added localhost to the list too.

We can also use * to match any host:


Finally, this fixed the error.

2. Remove the Corrupt extensions in Django

We received another error from one of our customers. 

The error was as below:

[09/Nov/2010 00:31:53] "GET /acq/ HTTP/1.1" 200 1393
[09/Nov/2010 00:31:53] code 400, message Bad request syntax ('\x16\x03\x00...')
?????????...." 400 -???8 .....?????
[09/Nov/2010 00:33:39] "GET /acq/ HTTP/1.1" 200 1393

Our Support Experts started troubleshooting this error by clearing the cache.

Then, we tried uninstalling all the extensions.

That did the trick. After the uninstallation, the error disappeared. 

We finally found that the trouble was with the Secure Sites extension which lets to access a secure website.

Finally, we fixed this error by adding localhost to "Assumed no secure version exists" within the extension's options.

3. Clearing the cache to fix 400 bad request error

The cache can also create problems. So we simply suggest our customers clear the cache and try checking if the error disappears.

Also, we suggest logging out from the framework and ask to login again and see if it works because the cached cookies will have the old login session.

[Need urgent assistance with Django errors? – We'll help you. ]


This article will guide you on methods to resolve the #Django 400 bad request which is caused due to many reasons which include incorrect syntax, corrupt extensions, incorrect URL, and so on.

The 400 Bad Request #error is an #HTTP status code that means that the request you sent to the website server, often something simple like a request to load a web page, was somehow incorrect or corrupted and the server couldn't understand it.

To resolve 400 Bad Request:

1. Check for errors in the URL.

2. Clear Browser Cache and cookies.

3. Clear DNS Cache.

4. Check your File upload Size.

5. Deactivate Browser Extensions.