[Django] #30906: Error in documentation: django.template.loader.render function does not accept Context objects

35 views
Skip to first unread message

Django

unread,
Oct 24, 2019, 4:19:29 AM10/24/19
to django-...@googlegroups.com
#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.

Django

unread,
Oct 24, 2019, 4:56:39 AM10/24/19
to django-...@googlegroups.com
#30906: Error in documentation: django.template.loader.render function does not
accept Context objects
-------------------------------------+-------------------------------------
Reporter: Philipp Maino | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: Context, template, | Triage Stage: Accepted
loader, render |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* easy: 0 => 1
* stage: Unreviewed => Accepted


Comment:

Yes, thank you. Good spot.

--
Ticket URL: <https://code.djangoproject.com/ticket/30906#comment:1>

Django

unread,
Oct 24, 2019, 4:58:25 AM10/24/19
to django-...@googlegroups.com
#30906: Error Outputting CSV code example. Template.render() does not accept
Context objects.

-------------------------------------+-------------------------------------
Reporter: Philipp Maino | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: Context, template, | Triage Stage: Accepted
loader, render |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/30906#comment:2>

Django

unread,
Oct 24, 2019, 6:24:44 AM10/24/19
to django-...@googlegroups.com
#30906: Error Outputting CSV code example. Template.render() does not accept
Context objects.
-------------------------------------+-------------------------------------
Reporter: Philipp Maino | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned

Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: Context, template, | Triage Stage: Accepted
loader, render |
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* status: new => assigned
* owner: nobody => Hasan Ramezani


--
Ticket URL: <https://code.djangoproject.com/ticket/30906#comment:3>

Django

unread,
Oct 24, 2019, 9:23:35 AM10/24/19
to django-...@googlegroups.com
#30906: Error Outputting CSV code example. Template.render() does not accept
Context objects.
-------------------------------------+-------------------------------------
Reporter: Philipp Maino | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 2.2
Severity: Normal | Resolution:
Keywords: Context, template, | Triage Stage: Accepted
loader, render |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/30906#comment:4>

Django

unread,
Oct 25, 2019, 2:12:31 AM10/25/19
to django-...@googlegroups.com
#30906: Error Outputting CSV code example. Template.render() does not accept
Context objects.
-------------------------------------+-------------------------------------
Reporter: Philipp Maino | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: closed
Component: Documentation | Version: 2.2
Severity: Normal | Resolution: fixed

Keywords: Context, template, | Triage Stage: Accepted
loader, render |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"05c3ef26a203de1bc227e31b88999ff2e3b11abf" 05c3ef26]:
{{{
#!CommitTicketReference repository=""
revision="05c3ef26a203de1bc227e31b88999ff2e3b11abf"
Fixed #30906 -- Fixed an example of using the template system to generate
CSV.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30906#comment:5>

Django

unread,
Oct 25, 2019, 2:13:12 AM10/25/19
to django-...@googlegroups.com
#30906: Error Outputting CSV code example. Template.render() does not accept
Context objects.
-------------------------------------+-------------------------------------
Reporter: Philipp Maino | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: closed
Component: Documentation | Version: 2.2
Severity: Normal | Resolution: fixed
Keywords: Context, template, | Triage Stage: Accepted
loader, render |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"6df42e6187121e641ea7250855f63edfb2ec005d" 6df42e61]:
{{{
#!CommitTicketReference repository=""
revision="6df42e6187121e641ea7250855f63edfb2ec005d"
[3.0.x] Fixed #30906 -- Fixed an example of using the template system to
generate CSV.

Backport of 05c3ef26a203de1bc227e31b88999ff2e3b11abf from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30906#comment:6>

Django

unread,
Oct 25, 2019, 2:13:34 AM10/25/19
to django-...@googlegroups.com
#30906: Error Outputting CSV code example. Template.render() does not accept
Context objects.
-------------------------------------+-------------------------------------
Reporter: Philipp Maino | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: closed
Component: Documentation | Version: 2.2
Severity: Normal | Resolution: fixed
Keywords: Context, template, | Triage Stage: Accepted
loader, render |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"9d627bf9b222758d8cccaecce53115cdd5bc1fa0" 9d627bf9]:
{{{
#!CommitTicketReference repository=""
revision="9d627bf9b222758d8cccaecce53115cdd5bc1fa0"
[2.2.x] Fixed #30906 -- Fixed an example of using the template system to
generate CSV.

Backport of 05c3ef26a203de1bc227e31b88999ff2e3b11abf from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30906#comment:7>

Reply all
Reply to author
Forward
0 new messages