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.
1 thought on “Solved: DisallowedHost – Invalid HTTP_HOST header”