I am creating a custom HTTP 500 error template. Why is it Django shows it when i raise an exception and not when I return HttpResponseServerError (I just get the default browser 500 error)? I find this behaviour strange…
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
HttpResponseServerErrorinherits fromHttpResponseand is actually quite simple:So let’s look at the
HttpResponseconstructor:As you can see by default
contentis empty.Now, let’s take a look at how it is called by Django itself (an excerpt from django.views.defaults):
As you can see when you produce a server error, the template named 500.html is used, but when you simply return
HttpResponseServerErrorthe content is empty and the browser falls back to it’s default page.