#30906: Error in documentation: django.template.loader.render function does not
accept Context objects
-------------------------------------+-------------------------------------
Reporter: Philipp | Owner: nobody
Maino |
Type: | Status: new
Cleanup/optimization |
Component: | Version: 2.2
Documentation | Keywords: Context, template,
Severity: Normal | loader, render
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
https://docs.djangoproject.com/en/3.0/howto/outputting-csv/
We can find in the section "Using the template system" in the docs about
"Outputing csv with django" the following code:
{{{#!python
t = loader.get_template('my_template_name.txt')
c = Context({
'data': csv_data,
})
response.write(t.render(c))
}}}
The django.template.loader.render is expecting a dict though and not a
Context object as we can see here:
{{{#!python
class Template:
def __init__(self, template, backend):
self.template = template
self.backend = backend
@property
def origin(self):
return self.template.origin
def render(self, context=None, request=None):
context = make_context(context, request,
autoescape=self.backend.engine.autoescape)
.
.
.
def make_context(context, request=None, **kwargs):
"""
Create a suitable Context from a plain dict and optionally an HttpRequest.
"""
if context is not None and not isinstance(context, dict):
raise TypeError('context must be a dict rather than %s.' %
context.__class__.__name__)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30906>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.5623a53d0e20b2e454b4ec29c3093674%40djangoproject.com.