Django custom 500 error template does not display request.user

I am implementing custom 404 and 500 templates, but although the 404.html template seems to return request.user.is_authenticated fine, the 500.html template does not return anything. I also checked for request.user and it is just empty on page 500.

This is very strange because when I run the 500 error, I get the expected error message error message, and it clearly has a USER correctly defined in the request breakdown. Here is the code I use in views.py:

def handler404(request): response = render_to_response('404.html', {}, context_instance=RequestContext(request)) response.status_code = 404 return response def handler500(request): response = render_to_response('500.html', {}, context_instance=RequestContext(request)) response.status_code = 500 return response 

I am wondering if something in the background (maybe in RequestContext) is processing 500 other than 404? I have to mention that I also use django-guardian, although I do not think that would affect anything in this case. Any ideas?

Edit: This comment states that "template 500 will not display request.user because it reports a server 500 error, so the server cannot serve anything." Does anyone know about this? It seems like there should be one, because, as I said, the log I get in the error message explicitly has a request object with a username.

Edit 2: Now I wonder if this is related to django-allauth - I use it too.

+4
django django-templates django-allauth django-errors
Sep 25 '14 at 16:08
source share
1 answer

I get it! I had to add the following line to urls.py:

 handler500 = "mysite.views.handler500" 

It’s very strange how 404 worked fine without an equivalent string, but 500 acts is really weird.

+3
Sep 26 '14 at 3:49
source share



All Articles