user7804233
user7804233

Reputation:

Django doesn't recognize DEBUG = False

I'm trying to develop 404 and 500 error custom templates for my Django project.

When I change DEBUG to False, Django always returns me:

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

After change ALLOWED_HOSTS to ['.domain.com', 'www.domain.com'] I obtain:

Invalid HTTP_HOST header: 'domain.com'. You may need to add u'domain.com' to ALLOWED_HOSTS.

What am I doing wrong? Why Django does not recognize the variable?

Upvotes: 0

Views: 6353

Answers (2)

Yannic Hamann
Yannic Hamann

Reputation: 5205

Find the DJANGO_SETTINGS_MODULE environment variable within your project.

The value of it is in python path syntax. Use it to locate the settings file since it is the one getting used by django and make sure that DEBUG = False. Additionally you could add a print statement which gives some visual feedback on server start.

Restart your development server after you have saved the configuration by executing python manage.py runserver.

Upvotes: 1

brandondavid
brandondavid

Reputation: 200

For what it's worth, when I create custom 404 / 500 templates I find it easier to setup a temporary class based TemplateView and then once I'm finished designing them they get moved into the templates folder where Django looks for them. The reason is, once you get past the DEBUG issue your next obstacle will likely be getting your static files served; in a typical setup they will not be served on your development machine when DEBUG = False (unless you've configured it to do so). It's significant because the template you are creating may rely upon those files (css, js files etc). Either way:

1) Make sure it reads exactly as:

DEBUG = False

2) Make sure it's not nested in kind of if / else statement or something like that.

3) In your development environment you can keep ALLOWED_HOSTS = ['localhost'] to suppress the domain warning.

4) If all else fails you could start a new project in a different directory and compare the auto generated settings.py file to what you have.

Upvotes: 0

Related Questions