summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorChris Beaven <smileychris@gmail.com>2011-02-20 04:55:11 +0000
committerChris Beaven <smileychris@gmail.com>2011-02-20 04:55:11 +0000
commit1073a83f2ceb330c80da275c0709786a7a84c513 (patch)
treeb3a1415e3d4865840aaed710f4d8831363b35742 /django
parent8ee9a4627e6716f24f529260928a1c36e7941e66 (diff)
Ensure render_to_string leaves the context instance stack in the state it was originally passed in.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15591 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/template/loader.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/django/template/loader.py b/django/template/loader.py
index 279d8e86fe..e58dc3231d 100644
--- a/django/template/loader.py
+++ b/django/template/loader.py
@@ -179,11 +179,15 @@ def render_to_string(template_name, dictionary=None, context_instance=None):
t = select_template(template_name)
else:
t = get_template(template_name)
- if context_instance:
- context_instance.update(dictionary)
- else:
- context_instance = Context(dictionary)
- return t.render(context_instance)
+ if not context_instance:
+ return t.render(Context(dictionary))
+ # Add the dictionary to the context stack, ensuring it gets removed again
+ # to keep the context_instance in the same state it started in.
+ context_instance.update(dictionary)
+ try:
+ return t.render(context_instance)
+ finally:
+ context_instance.pop()
def select_template(template_name_list):
"Given a list of template names, returns the first that can be loaded."