Skip to content

Instantly share code, notes, and snippets.

@Majunko
Last active April 30, 2019 17:30
Show Gist options
  • Save Majunko/4e1173645387338e7afe0467dfcc8861 to your computer and use it in GitHub Desktop.
Save Majunko/4e1173645387338e7afe0467dfcc8861 to your computer and use it in GitHub Desktop.
Custom errors page in Django 2.0 >=
from django.conf.urls import (
handler400, handler403, handler404, handler500
)
handler400 = 'myapp.views.handler400'
handler403 = 'myapp.views.handler403'
handler404 = 'myapp.views.handler404'
handler500 = 'myapp.views.handler500'
urlpatterns = [
...
]
from django.shortcuts import render
'''
Be sure of the correct path of html error page.
it's an example for django_project/templates/errors
errors/400.html
...
'''
def handler400(request, exception):
return render(request, 'errors/400.html', status=400)
def handler403(request, exception):
return render(request, 'errors/403.html', status=403)
def handler404(request, exception):
return render(request, 'errors/404.html', status=404)
def handler500(request):
return render(request, 'errors/500.html', status=500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment