Ticket #9081: flexible_render_to_response.2.diff

File flexible_render_to_response.2.diff, 2.2 KB (added by Brent Hagany, 16 years ago)

Updated patch to include docs

  • django/shortcuts/__init__.py

     
    1111
    1212def render_to_response(*args, **kwargs):
    1313    """
    14     Returns a HttpResponse whose content is filled with the result of calling
     14    Returns a HttpResponse (or subclass) whose content is filled with the result of calling
    1515    django.template.loader.render_to_string() with the passed arguments.
    1616    """
    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)
    1919
    2020def _get_queryset(klass):
    2121    """
  • docs/topics/http/shortcuts.txt

     
    1212========================
    1313
    1414``django.shortcuts.render_to_response`` renders a given template with a given
    15 context dictionary and returns an ``HttpResponse`` object with that rendered
    16 text.
     15context dictionary and returns an ``HttpResponse`` object, or subclass
     16thereof, with that rendered text.
    1717
    1818Required arguments
    1919------------------
     
    4848    The MIME type to use for the resulting document. Defaults to the value of
    4949    the :setting:`DEFAULT_CONTENT_TYPE` setting.
    5050
     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
    5162Example
    5263-------
    5364
Back to Top