15
15
from django .core .exceptions import ImproperlyConfigured
16
16
from django .core .paginator import Page
17
17
from django .http .multipartparser import parse_header
18
- from django .template import Context , RequestContext , Template , loader
18
+ from django .template import Template , loader
19
19
from django .test .client import encode_multipart
20
20
from django .utils import six
21
21
22
22
from rest_framework import VERSION , exceptions , serializers , status
23
23
from rest_framework .compat import (
24
- INDENT_SEPARATORS , LONG_SEPARATORS , SHORT_SEPARATORS
24
+ INDENT_SEPARATORS , LONG_SEPARATORS , SHORT_SEPARATORS , template_render
25
25
)
26
26
from rest_framework .exceptions import ParseError
27
27
from rest_framework .request import is_form_media_type , override_method
@@ -168,15 +168,15 @@ def render(self, data, accepted_media_type=None, renderer_context=None):
168
168
template = self .resolve_template (template_names )
169
169
170
170
context = self .resolve_context (data , request , response )
171
- return template . render ( context )
171
+ return template_render ( template , context , request = request )
172
172
173
173
def resolve_template (self , template_names ):
174
174
return loader .select_template (template_names )
175
175
176
176
def resolve_context (self , data , request , response ):
177
177
if response .exception :
178
178
data ['status_code' ] = response .status_code
179
- return RequestContext ( request , data )
179
+ return data
180
180
181
181
def get_template_names (self , response , view ):
182
182
if response .template_name :
@@ -230,7 +230,7 @@ def render(self, data, accepted_media_type=None, renderer_context=None):
230
230
request = renderer_context ['request' ]
231
231
template = self .get_exception_template (response )
232
232
context = self .resolve_context (data , request , response )
233
- return template . render ( context )
233
+ return template_render ( template , context , request = request )
234
234
235
235
return data
236
236
@@ -333,8 +333,8 @@ def render_field(self, field, parent_style):
333
333
template_name = style ['template_pack' ].strip ('/' ) + '/' + style ['base_template' ]
334
334
335
335
template = loader .get_template (template_name )
336
- context = Context ( {'field' : field , 'style' : style })
337
- return template . render ( context )
336
+ context = {'field' : field , 'style' : style }
337
+ return template_render ( template , context )
338
338
339
339
def render (self , data , accepted_media_type = None , renderer_context = None ):
340
340
"""
@@ -350,11 +350,11 @@ def render(self, data, accepted_media_type=None, renderer_context=None):
350
350
template_pack = style ['template_pack' ].strip ('/' )
351
351
template_name = template_pack + '/' + self .base_template
352
352
template = loader .get_template (template_name )
353
- context = Context ( {
353
+ context = {
354
354
'form' : form ,
355
355
'style' : style
356
- })
357
- return template . render ( context )
356
+ }
357
+ return template_render ( template , context )
358
358
359
359
360
360
class BrowsableAPIRenderer (BaseRenderer ):
@@ -600,8 +600,8 @@ def get_filter_form(self, data, view, request):
600
600
return
601
601
602
602
template = loader .get_template (self .filter_template )
603
- context = Context ( {'elements' : elements })
604
- return template . render ( context )
603
+ context = {'elements' : elements }
604
+ return template_render ( template , context )
605
605
606
606
def get_context (self , data , accepted_media_type , renderer_context ):
607
607
"""
@@ -672,8 +672,7 @@ def render(self, data, accepted_media_type=None, renderer_context=None):
672
672
673
673
template = loader .get_template (self .template )
674
674
context = self .get_context (data , accepted_media_type , renderer_context )
675
- context = RequestContext (renderer_context ['request' ], context )
676
- ret = template .render (context )
675
+ ret = template_render (template , context , request = renderer_context ['request' ])
677
676
678
677
# Munge DELETE Response code to allow us to return content
679
678
# (Do this *after* we've rendered the template so that we include
@@ -709,8 +708,7 @@ def render(self, data, accepted_media_type=None, renderer_context=None):
709
708
710
709
template = loader .get_template (self .template )
711
710
context = self .get_context (data , accepted_media_type , renderer_context )
712
- context = RequestContext (renderer_context ['request' ], context )
713
- ret = template .render (context )
711
+ ret = template_render (template , context , request = renderer_context ['request' ])
714
712
715
713
# Creation and deletion should use redirects in the admin style.
716
714
if (response .status_code == status .HTTP_201_CREATED ) and ('Location' in response ):
0 commit comments