Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#18369 closed Cleanup/optimization (fixed)

Documentation error with django.shortcuts.render() function

Reported by: qsolo825@… Owned by: timo
Component: Documentation Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I suppose there is one tiny error in description of django.shortcuts.render function in Django documentation
It's said there that its second argument named template. As I see from sources this function internally passes
almost all its argument to loader.render_to_string using *args and **kwargs like render_to_response do.
But loader.render_to_string is defined as

render_to_string(template_name, dictionary=None, context_instance=None)

so if you call render using key-words arguments e.g.

render(request=request, template='path/to/template.html')

or attempt to use it as simple view instead of TemplateView e.g

url(r'^some-url/$', render, {'template': 'path/to/template.html'})

you get TypeError with message "render_to_string() got an unexpected keyword argument 'template'".
I think it'll be better to use template_name as name of argument instead of template in documentation for the render shortcut.

Change History (4)

comment:1 Changed 4 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 4 years ago by timo

  • Owner changed from nobody to timo
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 4 years ago by Tim Graham <timgraham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In [1cf8287e3a6f252b79e9b9a8f945f11a92e17cd5]:

Fixed #18369 - Fixed argument name in render() function; thanks qsolo825@ for the report.

comment:4 Changed 4 years ago by Tim Graham <timgraham@…>

In [3631a028e2d8eef9ade7b174d9cbe1440d4acfad]:

[1.4.X] Fixed #18369 - Fixed argument name in render() function; thanks qsolo825@ for the report.

Backport of 1cf8287e3a from master

Note: See TracTickets for help on using tickets.
Back to Top