Created
February 3, 2011 17:04
-
-
Save revolunet/809780 to your computer and use it in GitHub Desktop.
add context to your django error pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# by default, django 404 and 500 pages dont pass context to templates. | |
# as you almost *always* need context variables in your custom | |
# 404/500 templates, you might need MEDIA_URL for example | |
# | |
# you need to create a custom view for errors and register it in your urls.py | |
# | |
# in urls.py add : | |
# | |
# handler500 = handler404 = views.server_error | |
# | |
# | |
def server_error(request, template_name='500.html'): | |
from django.template import RequestContext | |
from django.http import HttpResponseServerError | |
t = get_template(template_name) | |
return HttpResponseServerError(t.render(RequestContext(request))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of Django 1.11 i get {TypeError}context must be a dict rather than RequestContext.