Ticket #9081: flexible_render_to_response.2.diff
File flexible_render_to_response.2.diff, 2.2 KB (added by , 16 years ago) |
---|
-
django/shortcuts/__init__.py
11 11 12 12 def render_to_response(*args, **kwargs): 13 13 """ 14 Returns a HttpResponse whose content is filled with the result of calling14 Returns a HttpResponse (or subclass) whose content is filled with the result of calling 15 15 django.template.loader.render_to_string() with the passed arguments. 16 16 """ 17 httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)}18 return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)17 httpresponse_kwargs, response_class = {'mimetype': kwargs.pop('mimetype', None)}, kwargs.pop('response_class', HttpResponse) 18 return response_class(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs) 19 19 20 20 def _get_queryset(klass): 21 21 """ -
docs/topics/http/shortcuts.txt
12 12 ======================== 13 13 14 14 ``django.shortcuts.render_to_response`` renders a given template with a given 15 context dictionary and returns an ``HttpResponse`` object with that rendered16 t ext.15 context dictionary and returns an ``HttpResponse`` object, or subclass 16 thereof, with that rendered text. 17 17 18 18 Required arguments 19 19 ------------------ … … 48 48 The MIME type to use for the resulting document. Defaults to the value of 49 49 the :setting:`DEFAULT_CONTENT_TYPE` setting. 50 50 51 ``response_class`` 52 The response class to return. By default, the response class will be 53 HttpResponse. This is useful for things like returning HTTP status codes 54 other than 200, or adding your own custom functionality to your response, 55 while still retaining the convenience of render_to_response. For instance, 56 if you wish to return HTTP 400 (Bad Request), you may do this:: 57 58 return render_to_response('my_template.html', 59 my_data_dictionary, 60 response_class=HttpResponseBadRequest) 61 51 62 Example 52 63 ------- 53 64