Django 500 Error Request Context
Contents |
Previous TicketNext Ticket → Opened 9 years ago Closed 8 years ago Last modified 3 years ago #6377 closed Uncategorized (wontfix) Use RequestContext if possible in default 500 error view Reported by: Jason Davies Owned by: nobody Component:
Django Request Context Processor
Core (Other) Version: master Severity: Normal Keywords: error, handler500, 500 Cc: Triage Stage: django 500 error log Unreviewed Has patch: no Needs documentation: no Needs tests: no Patch needs improvement: no Easy pickings: no UI/UX: no
Django 500 Error Page
Description It would be nice if the default handler500 error view tried to use RequestContext by default, and fell back to using Context if an Exception is raised. Currently, various context django 500 error template variables such as MEDIA_URL are not populated in error pages, since only Context is being used. Attachments (1) defaults.py.diff (562 bytes) - added by Jason Davies 9 years ago. Download all attachments as: .zip Oldest first Newest first Threaded Show comments Show property changes Change History (7) Changed 9 years ago by Jason Davies Attachment: defaults.py.diff added comment:1 follow-up: 2 Changed 9 years ago django return 500 error by James Bennett Needs documentation: unset Needs tests: unset Patch needs improvement: unset Resolution: → duplicate Status: new → closed Duplicate of #5617, which was wontfix'd. See that ticket for the explanation, and please search the ticket archive in the future. comment:2 in reply to: 1 Changed 8 years ago by Jason Davies Resolution: duplicate Status: closed → reopened Replying to ubernostrum: Duplicate of #5617, which was wontfix'd. See that ticket for the explanation, and please search the ticket archive in the future. The explanation given was: The default server-error handler was deliberately written this way to lessen the odds of new exceptions being raised during the execution of the server_error view. I fully understand this reasoning. However, unlike the patches for #5617, my patch falls back to using the ordinary Context in the event of any new exceptions being raised. Is there any reason why this would be a bad idea? I have several clients who make heavy use of MEDIA_URL and so on for branding their sites, and the default 500 error handler looks rather ugly without any CSS or images, and thus confuses their customer
here for a quick overview of the site Help Center Detailed answers to any
Django Requestcontext
questions you might have Meta Discuss the workings and policies of django load template this site About Us Learn more about Stack Overflow the company Business Learn more about
Django Render_to_response
hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow https://code.djangoproject.com/ticket/6377 is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Django custom 500 error template not displaying request.user up vote 4 down vote favorite I'm implementing custom 404 and 500 templates, but while the 404.html template seems to return request.user.is_authenticated fine, http://stackoverflow.com/questions/26043211/django-custom-500-error-template-not-displaying-request-user the 500.html template fails to return anything. I also checked for request.user and it's just blank on the 500 page. This is very strange, because when I trigger the 500 error, I receive the expected error report e-mail, and it clearly has USER properly defined in the request breakdown. Here's the code I'm using 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'm wondering if something in the background (maybe in RequestContext) is treating the 500 different from the 404? I should mention that I'm also using django-guardian, though I don't think this would affect anything in the case. Any ideas? Edit: This comment claims "the 500 template won't render request.user because it is reporting a 500 server error, so the server is not able to serve up anything." Does anyone know a way around this?
the server. This seems like something http://cramer.io/2011/01/25/error-tracing-in-sentry insignificant, but it allows you to do something very powerful: trace errors from the customer or developer down to the precise request and log entry. Exposing Sentry ID The new IDs are generated automatically when a message is processed (by the client), so you won't need to make any changes on 500 error that end. Likely, however, you're going to want to expose these at your application level for a couple of different reasons. The first one we're going to cover is your customer's experience. The easiest way to expose this information in a useful manner, is by creating a modified 500.html. In django 500 error DISQUS' case, we mention the error reference ID to the end-user, so that when they're reporting a problem they can pass along this information. Create a custom 500 handler The first thing you're going to need to do is to create a custom 500 handler. This defined in urls.py, so we're just going to go ahead and create the view in-place. def handler500(request): """ An error handler which exposes the request object to the error template. """ from django.template import Context, loader from django.http import HttpResponseServerError from disqus.context_processors import default import logging import sys try: context = default(request) except Exception, e: logging.error(e, exc_info=sys