J
J
Jamaludin Osmanov2020-05-03 21:40:22
Django
Jamaludin Osmanov, 2020-05-03 21:40:22

How to write custom error pages in django admin?

The admin panel is connected to the django project.
In the case when an error appears in the admin panel, instead of the standard template with an error implemented for the entire site ('500.html'), you need to issue a template that is implemented for the admin panel itself ('admin/500.html').

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jamaludin Osmanov, 2020-05-05
@jamalosm

Did it like this:

#admin/views.py
from django.shortcuts import render_to_response
...
def handler500(request, *args, **kwargs):
    response = render_to_response('admin/500.html')
    response.status_code = 500
    return response

def handler404(request, *args, **kwargs):
    response = render_to_response('admin/404.html')
    response.status_code = 404
    return response
...

#admin/urls.py
...
handler404 = 'admin.views.handler404'
handler500 = 'admin.views.handler500'
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question