Deprecated some arguments of django.shortcuts.render(_to_response).

dictionary and context_instance and superseded by context.

Refactored tests that relied context_instance with more modern idioms.
This commit is contained in:
Aymeric Augustin 2014-12-14 10:17:18 +01:00
parent a0141f9eac
commit fdbfc98003
12 changed files with 137 additions and 92 deletions

View file

@ -15,7 +15,7 @@ introduce controlled coupling for convenience's sake.
``render``
==========
.. function:: render(request, template_name[, dictionary][, context_instance][, content_type][, status][, current_app][, dirs])
.. function:: render(request, template_name[, context][, context_instance][, content_type][, status][, current_app][, dirs])
Combines a given template with a given context dictionary and returns an
:class:`~django.http.HttpResponse` object with that rendered text.
@ -41,15 +41,24 @@ Required arguments
Optional arguments
------------------
``dictionary``
``context``
A dictionary of values to add to the template context. By default, this
is an empty dictionary. If a value in the dictionary is callable, the
view will call it just before rendering the template.
.. versionchanged:: 1.8
The ``context`` argument used to be called ``dictionary``. That name
is deprecated in Django 1.8 and will be removed in Django 2.0.
``context_instance``
The context instance to render the template with. By default, the template
will be rendered with a ``RequestContext`` instance (filled with values from
``request`` and ``dictionary``).
``request`` and ``context``).
.. deprecated:: 1.8
The ``context_instance`` argument is deprecated. Simply use ``context``.
``content_type``
The MIME type to use for the resulting document. Defaults to the value of
@ -67,7 +76,7 @@ Optional arguments
The ``dirs`` parameter was added.
.. versionchanged:: 1.8
.. deprecated:: 1.8
The ``dirs`` parameter was deprecated.
@ -99,7 +108,7 @@ This example is equivalent to::
``render_to_response``
======================
.. function:: render_to_response(template_name[, dictionary][, context_instance][, content_type][, dirs])
.. function:: render_to_response(template_name[, context][, context_instance][, content_type][, status][, dirs])
Renders a given template with a given context dictionary and returns an
:class:`~django.http.HttpResponse` object with that rendered text.
@ -116,32 +125,48 @@ Required arguments
Optional arguments
------------------
``dictionary``
``context``
A dictionary of values to add to the template context. By default, this
is an empty dictionary. If a value in the dictionary is callable, the
view will call it just before rendering the template.
.. versionchanged:: 1.8
The ``context`` argument used to be called ``dictionary``. That name
is deprecated in Django 1.8 and will be removed in Django 2.0.
``context_instance``
The context instance to render the template with. By default, the template
will be rendered with a :class:`~django.template.Context` instance (filled
with values from ``dictionary``). If you need to use :ref:`context
with values from ``context``). If you need to use :ref:`context
processors <subclassing-context-requestcontext>`, render the template with
a :class:`~django.template.RequestContext` instance instead. Your code
might look something like this::
return render_to_response('my_template.html',
my_data_dictionary,
my_context,
context_instance=RequestContext(request))
.. deprecated:: 1.8
The ``context_instance`` argument is deprecated. Simply use ``context``.
``content_type``
The MIME type to use for the resulting document. Defaults to the value of
the :setting:`DEFAULT_CONTENT_TYPE` setting.
``status``
The status code for the response. Defaults to ``200``.
.. versionchanged:: 1.8
The ``status`` parameter was added.
.. versionchanged:: 1.7
The ``dirs`` parameter was added.
.. versionchanged:: 1.8
.. deprecated:: 1.8
The ``dirs`` parameter was deprecated.