summaryrefslogtreecommitdiff
path: root/django/template
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2015-01-26 21:57:10 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2015-02-03 08:29:45 +0100
commit2133f3157eff853329bafb7fda74c3c8fb4eae42 (patch)
tree5bb262ab847c79b3f70d8a8888e267b2816b0373 /django/template
parenta53541852d5601232899e54d66e623bc163c6dc2 (diff)
Fixed #24168 -- Allowed selecting a template engine in a few APIs.
Specifically in rendering shortcuts, template responses, and class-based views that return template responses. Also added a test for render_to_response(status=...) which was missing from fdbfc980. Thanks Tim and Carl for the review.
Diffstat (limited to 'django/template')
-rw-r--r--django/template/response.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/django/template/response.py b/django/template/response.py
index ab9559853a..48295c5e05 100644
--- a/django/template/response.py
+++ b/django/template/response.py
@@ -16,7 +16,7 @@ class SimpleTemplateResponse(HttpResponse):
rendering_attrs = ['template_name', 'context_data', '_post_render_callbacks']
def __init__(self, template, context=None, content_type=None, status=None,
- charset=None):
+ charset=None, using=None):
if isinstance(template, Template):
warnings.warn(
"{}'s template argument cannot be a django.template.Template "
@@ -31,6 +31,8 @@ class SimpleTemplateResponse(HttpResponse):
self.template_name = template
self.context_data = context
+ self.using = using
+
self._post_render_callbacks = []
# _request stores the current request object in subclasses that know
@@ -73,9 +75,9 @@ class SimpleTemplateResponse(HttpResponse):
def resolve_template(self, template):
"Accepts a template object, path-to-template or list of paths"
if isinstance(template, (list, tuple)):
- return loader.select_template(template)
+ return loader.select_template(template, using=self.using)
elif isinstance(template, six.string_types):
- return loader.get_template(template)
+ return loader.get_template(template, using=self.using)
else:
return template
@@ -189,7 +191,8 @@ class TemplateResponse(SimpleTemplateResponse):
rendering_attrs = SimpleTemplateResponse.rendering_attrs + ['_request', '_current_app']
def __init__(self, request, template, context=None, content_type=None,
- status=None, current_app=_current_app_undefined, charset=None):
+ status=None, current_app=_current_app_undefined, charset=None,
+ using=None):
# As a convenience we'll allow callers to provide current_app without
# having to avoid needing to create the RequestContext directly
if current_app is not _current_app_undefined:
@@ -199,5 +202,5 @@ class TemplateResponse(SimpleTemplateResponse):
RemovedInDjango20Warning, stacklevel=2)
request.current_app = current_app
super(TemplateResponse, self).__init__(
- template, context, content_type, status, charset)
+ template, context, content_type, status, charset, using)
self._request = request