0

Is there a way for an url in django to be triggered when no pattern matched the url requested by the client, something like:

defaulturl = "/path/to/default/page"

errorpage = "/path/to/error/page"

Thank you!

user3015541
  • 347
  • 1
  • 2
  • 8

2 Answers2

0

You should create

404.html

file inside your TEMPLATE_DIRS path

dease
  • 2,975
  • 13
  • 39
  • 75
0

Yes, You do it with django inbuilt or custom handler.

In urls.py

from app.error_view import my_custom_404_view #app is actually your app name

handler404 = my_custom_404_view

and in error_view.py define method my_custom_404_view

> def my_custom_404_view(request, template_name='404.html'):
>     url_path = request.path_info
>     if not url_path.endswith('/'):
>         url_path = url_path + '/'
>         return http.HttpResponseRedirect(url_path) # its just a example , you can edit whatever you want too. :)
Vaibhav Kumar
  • 518
  • 3
  • 12