0
votes

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?

2
There's not enough information here. Setting DEBUG = False should work, so you need to provide more information on how to reproduce the problem. Perhaps you have changed the wrong settings file, or you haven't saved your settings file or restarted the server after making the change.Alasdair
I've added new information to the question. I use Nginx as serverP. Rodoreda
I just saw this after adding my answer, your development environment is serving the site with nginx? Or are you referring to your production environment?brandondavid
Please consider to upvote, accept or comment the answer if they solved your problem. It's The best way to say thanks to other people here at SO when they invest time in posting them. Thanks!Yannic Hamann

2 Answers

1
votes

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.

1
votes

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.