Search code examples
djangopython-3.xsqlitedjango-rest-frameworkdjango-views

Custom 404 and 500 pages in django with -> DEBUG = True


I want to present the sample of my website to a client and it isn't quite finished yet but it is very important for me to hide the errors and to not show my codebase which django does if a server error occurs in development mode. Like so - Django depicting what went wrong

Also I cannot turn DEBUG = False as in that case the media files aren't displayed as they are currently being served locally. Which won't be served if DEBUG = False.

So is there a way to serve media files locally with DEBUG = False or to display custom 404 and 500 pages with DEBUG = True.


Solution

  • I suggest you replace the standard Django 404 page TEMPORARILY.

    In your virtual environment, the path for the Django 404 template can be found at (yourenvironmentname)/lib/python3.8/site-packages/django/views/templates with the name technical_404.html and technical_500.html.

    Replace the following files with your custom 404 and 500 pages.