Code

Ticket #1504: templates_python.txt.diff

File templates_python.txt.diff, 1.5 KB (added by anonymous, 7 years ago)
Line 
1Index: templates_python.txt
2===================================================================
3--- templates_python.txt        (revision 6188)
4+++ templates_python.txt        (working copy)
5@@ -555,6 +555,41 @@
6 Django uses the template loaders in order according to the ``TEMPLATE_LOADERS``
7 setting. It uses each loader until a loader finds a match.
8 
9+The ``render_to_response()`` shortcut
10+=====================================
11+
12+Django provides a shortcut, ``django.shortcuts.render_to_response``, for loading a template, filling
13+its context, and returning `an HttpResponse object`_.
14+
15+**Required arguments:**
16+
17+    ``template``
18+        The full name of a template to use.
19+
20+**Optional arguments:**
21+
22+    ``context``
23+        A dictionary of values to add to the template
24+        context. By default, this is an empty dictionary. If a value in the
25+        dictionary is callable, the view will call it just before rendering
26+        the template.
27+
28+    ``mimetype``
29+        The MIME type to use for the resulting document. Defaults
30+        to the value of the ``DEFAULT_CONTENT_TYPE`` setting.
31+
32+**Example:**
33+
34+The following example renders the template ``myapp/index.html`` with the mimetype ``application/xhtml+xml``::
35+
36+    from django.shortcuts import render_to_response
37+   
38+    my_view(request):
39+        # View code here
40+        return render_to_response("myapp/index.html", {"foo": "bar"}, mimetype="application/xhtml+xml")
41+   
42+.. _an HttpResponse object: ../request_response/#httpresponse-objects
43+
44 Extending the template system
45 =============================
46