Custom Error 400/500 page in Django

109 views
Skip to first unread message

Sergiy Smertelny

unread,
Jan 3, 2017, 7:05:08 AM1/3/17
to Django users

There is some strange problem. When I do like this

def error_page(request):
    return HttpResponseBadRequest

it raises My custom error page that I listed in main URLconf. But when I pass and exception there - I got just a blank page with the text of exception. For example, view is something like this:

def error_page(request):
    return HttpResponseBadRequest('The error text')

And I get a blank page with the "The error text" text in body, but not my custom error page. How can I make Django use my Error page Template, but with error text?

I am using Python 3.5 and Django 1.10.4

ludovic coues

unread,
Jan 3, 2017, 7:19:13 AM1/3/17
to django...@googlegroups.com
In your first exemple, you return a class but in your second exemple
you return an instance of the class. That might explain the difference
you notice.

The documentation on HttpResponseBadRequest mention it is used like an
HttpResponse object and part 3 of the django tutorial show how to
render a template in a HttpResponse object:
https://docs.djangoproject.com/en/1.10/intro/tutorial03/#write-views-that-actually-do-something
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/29e5659d-bbb7-4bc5-b0f7-e491cb24f6bc%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42
Reply all
Reply to author
Forward
0 new messages