diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-01-03 19:06:36 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-01-07 21:54:22 +0100 |
| commit | eaa1a22341aef5b92f5c3cd682f01e61c4159262 (patch) | |
| tree | 6e760006ff1f84178f350771ce5d11ceacdf4d79 /django | |
| parent | 118592663dcb761fb269ead3ab8a4977bc2cd3a6 (diff) | |
Added a request argument to render_to_string.
This is for consistency with Template.render.
It adds a little bit of knowledge about HTTP requests in
django.template.loader but I think consistency trumps purity.
Diffstat (limited to 'django')
| -rw-r--r-- | django/template/loader.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/django/template/loader.py b/django/template/loader.py index d93b5e6b2b..c03690fbd1 100644 --- a/django/template/loader.py +++ b/django/template/loader.py @@ -80,7 +80,7 @@ def render_to_string(template_name, context=None, context_instance=_context_instance_undefined, dirs=_dirs_undefined, dictionary=_dictionary_undefined, - using=None): + request=None, using=None): """ Loads a template and renders it with a context. Returns a string. @@ -94,7 +94,7 @@ def render_to_string(template_name, context=None, template = select_template(template_name, using=using) else: template = get_template(template_name, using=using) - return template.render(context) + return template.render(context, request) else: # Some deprecated arguments were passed - use the legacy code path @@ -104,6 +104,11 @@ def render_to_string(template_name, context=None, # to Django templates. Remove Engine.render_to_string() at the # same time as this code path in Django 2.0. if isinstance(engine, DjangoTemplates): + if request is not None: + raise ValueError( + "render_to_string doesn't support the request argument " + "when some deprecated arguments are passed.") + continue # Hack -- use the internal Engine instance of DjangoTemplates. return engine.engine.render_to_string( template_name, context, context_instance, dirs, dictionary) |
