Solved: DisallowedHost – Invalid HTTP_HOST header

This error is related to “Installing Django and Django-REST Framework on ubuntu” , if you have Django application / server running on local ubuntu host as,

$ python manage.py runserver

Then this server is started with binding to your local loopback IP address and default port as,

Starting development server at http://127.0.0.1:8000/

Now, when you decide to use your IP address instead of local loopback and also change the port, you can start the webserver as,

$ python manage.py runserver 192.168.0.103:8080

Considering, your IP address is “192.168.0.103” (it can be different in your case) and port you want to use as “8080” ( This also can be different as you want)

Now, the server will get started but when you visit in browser as, http://192.168.0.103:8080/ you may see an error as,

DisallowedHost at /
Invalid HTTP_HOST header: ‘192.168.0.103:8080’. You may need to add ‘192.168.0.103’ to ALLOWED_HOSTS.

Request Method:GET
Request URL:http://192.168.0.103:8080/
Django Version:3.0.7
Exception Type:DisallowedHost
Exception Value:Invalid HTTP_HOST header: ‘192.168.0.103:8080’. You may need to add ‘192.168.0.103’ to ALLOWED_HOSTS.

Solution :

Open YOUR_PROJECT/settings.py and add the IP address ( in our case 192.168.0.103) as,

ALLOWED_HOSTS = ['192.168.0.103']

and restart the server as,

$ python manage.py runserver 192.168.0.103:8080

Now, if you visit the URL in browser http://192.168.0.103:8080 , you should not see the error.

How to remove index.php from URL in... x
How to remove index.php from URL in CodeIgniter using .htaccess

1 thought on “Solved: DisallowedHost – Invalid HTTP_HOST header”

Leave a Comment

Sign up to our newsletter!

ADB Commands Android Android Applications Android Build system Application Libraries Application Stack / User Interface Bash / Shell Scripts Bluetooth driver Cloud Technologies Commands and Packages Compilation Content Management System Core Kernel C Programs Development, Debugging and Performance Tools Development and Build Development Environment Setup Django & REST Api Errors & Failures Git Hardware Platforms HTML JAVA Programs Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Multimedia NDK / Middleware / HAL Operating System Concepts PHP Programming Languages Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Source Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Web Design and Development Website Hosting Wordpress Yocto Embedded Linux