~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to docs/topics/http/shortcuts.txt

  • Committer: Package Import Robot
  • Author(s): Raphaël Hertzog
  • Date: 2014-09-17 14:15:11 UTC
  • mfrom: (1.3.17) (6.2.18 experimental)
  • Revision ID: package-import@ubuntu.com-20140917141511-icneokthe9ww5sk4
Tags: 1.7-2
* Release to unstable.
* Add a migrate-south sample script to help users apply their South
  migrations. Thanks to Brian May.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
``render``
16
16
==========
17
17
 
18
 
.. function:: render(request, template_name[, dictionary][, context_instance][, content_type][, status][, current_app])
 
18
.. function:: render(request, template_name[, dictionary][, context_instance][, content_type][, status][, current_app][, dirs])
19
19
 
20
20
   Combines a given template with a given context dictionary and returns an
21
21
   :class:`~django.http.HttpResponse` object with that rendered text.
22
22
 
23
23
   :func:`render()` is the same as a call to
24
 
   :func:`render_to_response()` with a `context_instance` argument that
 
24
   :func:`render_to_response()` with a ``context_instance`` argument that
25
25
   forces the use of a :class:`~django.template.RequestContext`.
26
26
 
27
27
   Django does not provide a shortcut function which returns a
55
55
    The MIME type to use for the resulting document. Defaults to the value of
56
56
    the :setting:`DEFAULT_CONTENT_TYPE` setting.
57
57
 
58
 
    .. versionchanged:: 1.5
59
 
 
60
 
        This parameter used to be called ``mimetype``.
61
 
 
62
58
``status``
63
59
    The status code for the response. Defaults to ``200``.
64
60
 
67
63
    :ref:`namespaced URL resolution strategy <topics-http-reversing-url-namespaces>`
68
64
    for more information.
69
65
 
 
66
``dirs``
 
67
    A tuple or list of values to override the :setting:`TEMPLATE_DIRS` setting.
 
68
 
 
69
.. versionchanged:: 1.7
 
70
 
 
71
   The ``dirs`` parameter was added.
 
72
 
70
73
Example
71
74
-------
72
75
 
92
95
        return HttpResponse(t.render(c),
93
96
            content_type="application/xhtml+xml")
94
97
 
 
98
If you want to override the :setting:`TEMPLATE_DIRS` setting, use the
 
99
``dirs`` parameter::
 
100
 
 
101
    from django.shortcuts import render
 
102
 
 
103
    def my_view(request):
 
104
        # View code here...
 
105
        return render(request, 'index.html', dirs=('custom_templates',))
95
106
 
96
107
``render_to_response``
97
108
======================
98
109
 
99
 
.. function:: render_to_response(template_name[, dictionary][, context_instance][, content_type])
 
110
.. function:: render_to_response(template_name[, dictionary][, context_instance][, content_type][, dirs])
100
111
 
101
112
   Renders a given template with a given context dictionary and returns an
102
113
   :class:`~django.http.HttpResponse` object with that rendered text.
134
145
    The MIME type to use for the resulting document. Defaults to the value of
135
146
    the :setting:`DEFAULT_CONTENT_TYPE` setting.
136
147
 
137
 
    .. versionchanged:: 1.5
138
 
 
139
 
        This parameter used to be called ``mimetype``.
140
 
 
 
148
``dirs``
 
149
    A tuple or list of values to override the :setting:`TEMPLATE_DIRS` setting.
 
150
 
 
151
.. versionchanged:: 1.7
 
152
 
 
153
   The ``dirs`` parameter was added.
141
154
 
142
155
Example
143
156
-------
164
177
        return HttpResponse(t.render(c),
165
178
            content_type="application/xhtml+xml")
166
179
 
 
180
If you want to override the :setting:`TEMPLATE_DIRS` setting, use the
 
181
``dirs`` parameter::
 
182
 
 
183
    from django.shortcuts import render_to_response
 
184
 
 
185
    def my_view(request):
 
186
        # View code here...
 
187
        return render_to_response('index.html', dirs=('custom_templates',))
 
188
 
167
189
``redirect``
168
190
============
169
191
 
181
203
     <django.core.urlresolvers.reverse>` will be used to reverse-resolve the
182
204
     name.
183
205
 
184
 
   * A URL, which will be used as-is for the redirect location.
 
206
   * An absolute or relative URL, which will be used as-is for the redirect
 
207
     location.
185
208
 
186
209
   By default issues a temporary redirect; pass ``permanent=True`` to issue a
187
 
   permanent redirect
 
210
   permanent redirect.
 
211
 
 
212
   .. versionchanged:: 1.7
 
213
 
 
214
       The ability to use relative URLs was added.
188
215
 
189
216
Examples
190
217
--------