mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
Fixed #21741 -- Fixed render_to_string to stop pushing empty dictionaries to its Context
Thanks to kezabelle for the report and original patch and to numerodix for his improved patch.
This commit is contained in:
@@ -164,13 +164,14 @@ def render_to_string(template_name, dictionary=None, context_instance=None,
|
||||
get_template, or it may be a tuple to use select_template to find one of
|
||||
the templates in the list. Returns a string.
|
||||
"""
|
||||
dictionary = dictionary or {}
|
||||
if isinstance(template_name, (list, tuple)):
|
||||
t = select_template(template_name, dirs)
|
||||
else:
|
||||
t = get_template(template_name, dirs)
|
||||
if not context_instance:
|
||||
return t.render(Context(dictionary))
|
||||
if not dictionary:
|
||||
return t.render(context_instance)
|
||||
# Add the dictionary to the context stack, ensuring it gets removed again
|
||||
# to keep the context_instance in the same state it started in.
|
||||
with context_instance.push(dictionary):
|
||||
|
||||
Reference in New Issue
Block a user