VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-fix-django-error-disallowedhost-at-invalid-httphost-header/

⇱ How to Fix Django Error: DisallowedHost at / Invalid HTTP_HOST Header - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Fix Django Error: DisallowedHost at / Invalid HTTP_HOST Header

Last Updated : 23 Jul, 2025

Django is a full-stack Python framework for building websites. Sometimes, We might see a "DisallowedHost" error. This happens when the website’s address isn’t on a list of allowed addresses in your Django settings. Sometimes this error occurs when a proxy server tries to interact with our Django server for example gunicorn. In this article, we’ll go over how to fix this by changing the ALLOWED_HOSTS setting in Django.

Modifying ALLOWED_HOSTS

The ALLOWED_HOSTS setting in Django is a list of the website addresses or domain names that your Django site is allowed to serve. If someone tries to visit your site using an address not on this list, Django will show a DisallowedHost error. To fix this, just add the correct domain name or IP address to the ALLOWED_HOSTS list in your Django project's settings file.

Code Example

  1. Open your Django settings.py file: The settings file is usually located at myproject/settings.py.
  2. Find the ALLOWED_HOSTS setting: If it’s not already in the file, you can add it.
  3. Add the correct domain names or IP addresses: If your site is hosted on www.example.com, you would add 'www.example.com' to the list. If you’re running the site on your local machine using localhost, you should add 'localhost' as well.

settings.py


4. Wildcard Subdomains: If you want to allow all subdomains of a specific domain, you can use a wildcard.


5. Save and Restart: After modifying the ALLOWED_HOSTS setting, save the changes and restart your Django server to apply the new configuration.

Conclusion:

The DisallowedHost error in Django can be annoying, but it's simple to fix. Just add the host or domain name causing the error to the ALLOWED_HOSTS list in your settings. Don't forget to restart your Django server after making the change. This quick fix will help get your Django app working smoothly again.

Comment
Article Tags: