2
In order to show customized HTML when Django returns a 404, you can create an HTML template named 404.html and place it in the top level of your template tree. This template will then be served when DEBUG is set to False.
https://docs.djangoproject.com/en/dev/topics/http/views/#the-404-page-not-found-view
Also, there is an useful section βCustomizing error viewsβ.
And in the case you want to test your template withour turning DEBUG=False, you can run manage.py runserver --insecure
.
It will force Django to serving static files with the staticfiles app even if the DEBUG setting is False. But note that it it only for local development and could be insecure. You can read more about this option here.
0
Here is a quote from the Django doc:
This template should be called 404.html and located in the top level of your template tree.
Check here for the full text; for non 1.8 doc it should be somewhere around here: Writing views > Returning errors > The Http404 exception.
- [Answered ]-Using two models on the same Admin page
- [Answered ]-How turn {{ fieldset.fields }} in Django template into a string?
- [Answered ]-Django serve multiple domains with a single instance
- [Answered ]-Saving an image into user model
0
You should create following view:
def custom404(request):
return render(request, '404.html', status=404)
And connect it with following construction in urls.py
:
handler404 = 'path.to.views.custom404'
- [Answered ]-Why do I get a "SSL error: called a function you should not call" with Django
- [Answered ]-Converting Django models queryset into a numpy matrix
- [Answered ]-How can I get rid of legacy tasks still in the Celery / RabbitMQ queue?
- [Answered ]-Django JsonResponse return no data