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!
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!
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. :)