You may need to add u'127.0.0.1' to ALLOWED_HOSTS

Question:

I am getting the following error when I am trying to start my Django server

python  manage.py runserver 0.0.0.0:8000

Performing system checks...

System check identified no issues (0 silenced).
August 18, 2019 - 20:47:09
Django version 1.11, using settings 'config.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
Invalid HTTP_HOST header: '127.0.0.1:8000'. You may need to add u'127.0.0.1' to ALLOWED_HOSTS.
Invalid HTTP_HOST header: '127.0.0.1:8000'. You may need to add u'127.0.0.1' to ALLOWED_HOSTS.
Invalid HTTP_HOST header: '127.0.0.1:8000'. You may need to add u'127.0.0.1' to ALLOWED_HOSTS.
Invalid HTTP_HOST header: '127.0.0.1:8000'. You may need to add u'127.0.0.1' to ALLOWED_HOSTS.
Invalid HTTP_HOST header: '127.0.0.1:8000'. You may need to add u'127.0.0.1' to ALLOWED_HOSTS.
Invalid HTTP_HOST header: '127.0.0.1:8000'. You may need to add u'127.0.0.1' to ALLOWED_HOSTS.
[18/Aug/2019 20:47:09] "GET /view/stockprice/ HTTP/1.1" 400 16918
[18/Aug/2019 20:47:09] "GET /view/stockprice/ HTTP/1.1" 400 16918
[18/Aug/2019 20:47:09] "GET /view/stockprice/ HTTP/1.1" 400 16918
Invalid HTTP_HOST header: '127.0.0.1:8000'. You may need to add u'127.0.0.1' to ALLOWED_HOSTS.

I have already given 127.0.0.1 in the list of ALLOWED_HOST.

SECRET_KEY=BeatTheStreet

DEBUG=True

ALLOWED_HOSTS=['127.0.0.1', '0.0.0.0']

EVENT_STARTED=True
EVENT_ENDED=

# Production database details
DB_NAME=
DB_USER=
DB_PASSWORD=
DB_HOST=
DB_PORT=

Pointers to fix this will really help.

I am running server with 0.0.0.0:8000 because of issue I had in Django app not opening from different machine

Asked By: ThinkGeek

||

Answers:

This happens just because localhost of your host machine is not localhost of your host server. You can either do

ALLOWED_HOSTS=['<your host ip address>',]

or

ALLOWED_HOSTS=['*',]

although wildcard is not recommended, but useful in dev mode.

enter image description here
in the given ifconfig, the inet addr 192.168.1.104 is the ip of your host machine, if run ifconfig in the host

Answered By: All Іѕ Vаиітy

If after adding ‘*’ it still doesn’t work, you have to find ‘request.py’ file in venv and add your host by yourself: allowed_hosts = "your host"

Answered By: Shako Davitashvili
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.