Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit 9c2bbd6

Browse files
ismsashwoods
authored andcommitted
Update Django message ref example for 1.11, fixes #993
- Use a `TemplateResponse` (backwards compatible to Django 1.7) instead of trying to pass a `Context` object to an instance of `django.template.backends.django.Template.render` which is no longer allowed (see #993) - Verified working with example app (Python 3.5, Django 1.11) before changing example in docs
1 parent bc9d996 commit 9c2bbd6

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

docs/integrations/django.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ reference ID. The first step in doing this is creating a custom
196196
from django.conf.urls.defaults import *
197197

198198
from django.views.defaults import page_not_found, server_error
199-
from django.template import Context, loader
200-
from django.http import HttpResponseServerError
199+
from django.template.response import TemplateResponse
201200

202201
def handler500(request):
203202
"""500 error handler which includes ``request`` in the context.
@@ -206,10 +205,9 @@ reference ID. The first step in doing this is creating a custom
206205
Context: None
207206
"""
208207

209-
t = loader.get_template('500.html') # You need to create a 500.html template.
210-
return HttpResponseServerError(t.render(Context({
211-
'request': request,
212-
})))
208+
context = {'request': request}
209+
template_name = '500.html' # You need to create a 500.html template.
210+
return TemplateResponse(request, template_name, context, status=500)
213211

214212
Once we've successfully added the :data:`request` context variable, adding the
215213
Sentry reference ID to our :file:`500.html` is simple:

0 commit comments

Comments
 (0)