Django - invalid http_host header you may need to add to allowed_hosts

This error message is a security feature in Django that is designed to prevent HTTP Host header attacks. It occurs when the Host header in an incoming request does not match any of the values in the ALLOWED_HOSTS setting in your Django project's settings.

Invalid http_host header you may need to add to allowed_hosts [Solution]

To resolve this error, you need to add the correct Host value to the ALLOWED_HOSTS setting. Here's how:

  1. Open the file in your Django project.
  2. Find the ALLOWED_HOSTS setting and add your HOST value there. If you are using as a host then you can use - ALLOWED_HOSTS = [''].

If you are using localhost as your host then you can change your file as below.

ALLOWED_HOSTS = ["localhost", ""]

Add the correct Host value to the list. For example, if your website's domain is, you would add it like this:


If your website has multiple subdomains, you may also need to add those to the list. For example:

ALLOWED_HOSTS = ['', '', '']

Save the file and restart your Django development server. The invalid http_host header error should be resolved.

Note: Be sure to use the correct domain and subdomain names in the ALLOWED_HOSTS setting, as this is a critical security feature. If you're not sure what values to use, check with your web hosting provider or DNS administrator.

Was this helpful?