[Django]-How can I return a 404 error page when user hits a wrong url in django?

3👍

You need just prepare 404.html template and set DEBUG=False in your settings.py

0👍

Or if you want a custom 404 page, you just need to set the 404 handler adding in your main urls.py :

handler404 = 'mysite.views.my_custom_404_view'

https://docs.djangoproject.com/en/dev/topics/http/views/#customizing-error-views

👤Mibou

0👍

Create a 404.html file in your template folder

add this code to your view

from django.shortcuts import render

def handler404(request):
    return render(request, ’404.html’)

and in urls.py

handler404 = ‘mysite.views.handler404′

👤Anoop

Leave a comment