I’m trying to set up my 404 and 500 error pages but if I turn debug to false and go to an invalid url another error page appears which isnt mine. How can I fix that? urls.py
app_name = 'home'
urlpatterns = [
path('404/', views.view_404, name="404"),
path('500/', views.view_500, name="500"),
handler404 = 'StartSite.views.view_404'
handler500 = 'StartSite.views.view_500'
def view_404(request, exception=None):
return render(request, 'home/404.html', status=404)
return render(request, 'home/500.html')
You don’ t need to map the templates with a view, only put your 404.html and 500.html files inside the “templates” directory in any of the apps of your Django project.
and what should he put in the handlers and in the urls view path instead of the link from the view?
Nothing, you just need the templates. If you want to test the 404 go to an inexistent URL.
If you do want a custom view, you need to assign the view to the handler, not a string representing the view:
handler404 = StartSite.views.view_404
handler404 = 'StartSite.views.view_404')
Also, you do not need those entries in the urlpatterns. The sample in the doc is only there to give you a url to test the error.