Djano 404 Page Django.How

Author avatar wrote on 26/05/2022

Create page

Create a page 404.html and add it to the template folder

Test it

In the default settings.py file Django sets DEBUG = True and ALLOWED_HOSTS = []. We want to change both. Turning off debug will show us what a live site would show and ALLOWED_HOSTS restricts which HTTP requests Django will respond to so the URL needs to be explicitly added.


# demo_project/settings.py
DEBUG = False



ALLOWED_HOSTS = ['127.0.0.1']

Load static file when debug = False

When debug is False, django won’t load the static files

There is an extra option to be used with runserver command which forces Django to serve static files even when DEBUG=False


python manage.py runserver --insecure

Django docs ref: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#cmdoption-runserver-insecure

Resources:

CRUDgen Django CRUD generator