1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +00:00

[soc2009/http-wsgi-improvements] Update the render_to_response shortcut to pass request and content_type to HttpResponse, to support Accept-Charset. Refs #10190.

Also updates docs.

git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/http-wsgi-improvements@11378 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Chris Cahoon 2009-08-03 02:17:12 +00:00
parent edcc1c2e7e
commit 1da736f0f9
2 changed files with 18 additions and 4 deletions

View File

@ -11,12 +11,13 @@ from django.db.models.manager import Manager
from django.db.models.query import QuerySet from django.db.models.query import QuerySet
from django.core import urlresolvers from django.core import urlresolvers
accepted_kwargs = ('content_type', 'mimetype', 'request')
def render_to_response(*args, **kwargs): def render_to_response(*args, **kwargs):
""" """
Returns a HttpResponse whose content is filled with the result of calling Returns a HttpResponse whose content is filled with the result of calling
django.template.loader.render_to_string() with the passed arguments. django.template.loader.render_to_string() with the passed arguments.
""" """
httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)} httpresponse_kwargs = dict([(k, kwargs.pop(k, None)) for k in accepted_kwargs])
return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs) return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
def redirect(to, *args, **kwargs): def redirect(to, *args, **kwargs):

View File

@ -17,7 +17,7 @@ introduce controlled coupling for convenience's sake.
``render_to_response`` ``render_to_response``
====================== ======================
.. function:: render_to_response(template[, dictionary][, context_instance][, mimetype]) .. function:: render_to_response(template[, dictionary][, context_instance][, mimetype, content_type, status])
Renders a given template with a given context dictionary and returns an Renders a given template with a given context dictionary and returns an
:class:`~django.http.HttpResponse` object with that rendered text. :class:`~django.http.HttpResponse` object with that rendered text.
@ -48,12 +48,25 @@ Optional arguments
my_data_dictionary, my_data_dictionary,
context_instance=RequestContext(request)) context_instance=RequestContext(request))
``content_type``
.. versionadded:: 1.2
The value for the Content-Type header to use in the resulting document. Can
also contain a MIME type. Defaults to the value of the :setting:`DEFAULT_CONTENT_TYPE` setting.
``mimetype`` ``mimetype``
.. versionadded:: 1.0 .. versionadded:: 1.0
The MIME type to use for the resulting document. Defaults to the value of Alias for content_type, for backwards compatibility. Defaults to the value of
the :setting:`DEFAULT_CONTENT_TYPE` setting. the :setting:`DEFAULT_CONTENT_TYPE` setting.
``request``
.. versionadded:: 1.2
The request can be passed to HttpResponse for handling the Accept-Charset
header, which allows clients to specify the encoding in which they wish to
receive the content.
Example Example
------- -------