| 558 | The ``render_to_response()`` shortcut |
| 559 | ===================================== |
| 560 | |
| 561 | Django provides a shortcut, ``django.shortcuts.render_to_response``, for loading a template, filling |
| 562 | its 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 | |
| 583 | The 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 | |