[Answer]-Returning a function call instead of a HTTP response in a view

1👍

render_to_response is just a shortcut. Result of calling it is still HttpResponse‘s instance.

As a proof, see render_to_response()‘s declaration in source of Django:

def render_to_response(*args, **kwargs):
    """
    Returns a HttpResponse whose content is filled with the result of calling
    django.template.loader.render_to_string() with the passed arguments.
    """
    httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)}
    return HttpResponse(loader.render_to_string(*args, **kwargs),
        **httpresponse_kwargs)

Pretty self-explanatory.

By writing this:

return get_page(request, **kwargs)

you actually do something like:

return render_to_response(request, kwargs)

(but with slightly altered kwargs argument).

👤Tadeck

Leave a comment