#29960: `render_to_string` passes `None` for `context` if unspecified, but
`Template.render` expects type `Context`
-------------------------------------+-------------------------------------
Reporter: Joshua | Owner: nobody
Cannon |
Type: Bug | Status: new
Component: Template | Version: 2.1
system | Keywords: render_to_string,
Severity: Normal | template, context
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
I'm not sure if this is a bug bug or just misleading documentation, but
the signature/docstring for `render_to_string` starts as follows:
{{{
def render_to_string(template_name, context=None, request=None,
using=None):
"""
Load a template and render it with a context. Return a string.
...
}}}
The docstring would lead the reader to believe the context isn't optional.
If the caller omits `context`, they will likely get the following
exception:
{{{AttributeError: 'NoneType' object has no attribute 'render_context'}}}
which is due to `Template.render`'s first line being:
{{{
def render(self, context):
with context.render_context.push_state(self):
...
}}}
The signature of `Template.render` would lead me to believe context is not
optional and must be of type `Context`.
--
Ticket URL: <https://code.djangoproject.com/ticket/29960>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.b9058af0b099901fd1c600c0e79d1a16%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.