mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #12815 -- Added TemplateResponse, a lazy-evaluated Response class. Thanks to Simon Willison for the original idea, and to Mikhail Korobov and Ivan Sagalaev for their assistance, including the draft patch from Mikhail.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14850 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -133,6 +133,27 @@ can also add special translator comments in the source.
|
||||
For more information, see :ref:`contextual-markers` and
|
||||
:ref:`translator-comments`.
|
||||
|
||||
TemplateResponse
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
It can sometimes be beneficial to allow decorators or middleware to
|
||||
modify a response *after* it has been constructed by the view. For
|
||||
example, you may want to change the template that is used, or put
|
||||
additional data into the context.
|
||||
|
||||
However, you can't (easily) modify the content of a basic
|
||||
:class:`~django.http.HttpResponse` after it has been constructed. To
|
||||
overcome this limitation, Django 1.3 adds a new
|
||||
:class:`~django.template.TemplateResponse` class. Unlike basic
|
||||
:class:`~django.http.HttpResponse` objects,
|
||||
:class:`~django.template.TemplateResponse` objects retain the details
|
||||
of the template and context that was provided by the view to compute
|
||||
the response. The final output of the response is not computed until
|
||||
it is needed, later in the response process.
|
||||
|
||||
For more details, see the :ref:`documentation </ref/template-response>`
|
||||
on the :class:`~django.template.TemplateResponse` class.
|
||||
|
||||
Everything else
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user