Ticket #1504: 1504.diff

File 1504.diff, 2.4 KB (added by Maura Chace, 17 years ago)

diff for code and docs

  • django/shortcuts/__init__.py

     
    1414    Returns a HttpResponse whose content is filled with the result of calling
    1515    django.template.loader.render_to_string() with the passed arguments.
    1616    """
    17     return HttpResponse(loader.render_to_string(*args, **kwargs))
     17    if "mimetype" in kwargs:
     18        mimetype = kwargs["mimetype"]
     19        del kwargs["mimetype"]
     20        return HttpResponse(loader.render_to_string(*args, **kwargs), mimetype=mimetype)
     21    else:
     22        return HttpResponse(loader.render_to_string(*args, **kwargs))
    1823load_and_render = render_to_response # For backwards compatibility.
    1924
    2025def _get_queryset(klass):
  • docs/templates_python.txt

     
    555555Django uses the template loaders in order according to the ``TEMPLATE_LOADERS``
    556556setting. It uses each loader until a loader finds a match.
    557557
     558The ``render_to_response()`` shortcut
     559=====================================
     560
     561Django provides a shortcut, ``django.shortcuts.render_to_response``, for loading a template, filling
     562its context, and returning `an HttpResponse object`_.
     563
     564**Required arguments:**
     565
     566    ``template``
     567        The full name of a template to use.
     568
     569**Optional arguments:**
     570
     571    ``context``
     572        A dictionary of values to add to the template
     573        context. By default, this is an empty dictionary. If a value in the
     574        dictionary is callable, the view will call it just before rendering
     575        the template.
     576
     577    ``mimetype``
     578        The MIME type to use for the resulting document. Defaults
     579        to the value of the ``DEFAULT_CONTENT_TYPE`` setting.
     580
     581**Example:**
     582
     583The following example renders the template ``myapp/index.html`` with the mimetype ``application/xhtml+xml``::
     584
     585    from django.shortcuts import render_to_response
     586   
     587    my_view(request):
     588        # View code here
     589        return render_to_response("myapp/index.html", {"foo": "bar"}, mimetype="application/xhtml+xml")
     590   
     591.. _an HttpResponse object: ../request_response/#httpresponse-objects
     592
    558593Extending the template system
    559594=============================
    560595
Back to Top