python – Why disabling DEBUG in Django does not recognize static files anymore

Question:

Why is it that when disabling DEBUG in Django , static files, such as CSS , images, or JS are no longer recognized? I disable it to bring up custom error pages, but disabling DEBUG all styles are removed. I would appreciate it very much, if you would tell me what I am missing, or what I am doing wrong.

In the settings.py file:

DEBUG = False

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = ["localhost"]

In the views.py file:

def handler404(request):
    return render(request,'error/404.html')

Answer:

When you disable DEBUG , Django will stop handling static files. In that case your production server should do it.

In order to display your custom error page, you must create a template called 404.html and place it at the root of your template directory.

Here you find more detailed information:

Scroll to Top