Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I am new to Django-1.6. When I run the Django server with DEBUG = True, it's running perfectly. But when I change DEBUG to False in the settings file, then the server stopped and it gives the following error on the command prompt:

CommandError: You must set settings.ALLOWED_HOSTS if DEBUG is False.

After I changed ALLOWED_HOSTS to ["http://127.0.0.1:8000",], in the browser I get the error:

Bad Request (400)

Is it possible to run Django without debug mode?

1 Answer

0 votes
by (106k points)

The ALLOWED_HOSTS list should contain fully qualified hostnames, not URLs. Leave out the port and the protocol. If you are using 127.0.0.1, I would add localhost to the list too:

ALLOWED_HOSTS = ['127.0.0.1', 'localhost']

You could also use * to match any host:

ALLOWED_HOSTS = ['*']

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...