PageRenderTime 102ms CodeModel.GetById 60ms app.highlight 1ms RepoModel.GetById 39ms app.codeStats 1ms

/docs/topics/http/decorators.txt

https://code.google.com/p/mango-py/
Plain Text | 85 lines | 54 code | 31 blank | 0 comment | 0 complexity | 02a4ccad91067ed394db1add38789aa7 MD5 | raw file
 1===============
 2View decorators
 3===============
 4
 5.. module:: django.views.decorators.http
 6
 7Django provides several decorators that can be applied to views to support
 8various HTTP features.
 9
10Allowed HTTP methods
11====================
12
13The decorators in :mod:`django.views.decorators.http` can be used to restrict
14access to views based on the request method. These decorators will return
15a :class:`django.http.HttpResponseNotAllowed` if the conditions are not met.
16
17.. function:: require_http_methods(request_method_list)
18
19This decorator is used to ensure that a view only accepts particular request
20methods. Usage::
21
22    from django.views.decorators.http import require_http_methods
23
24    @require_http_methods(["GET", "POST"])
25    def my_view(request):
26        # I can assume now that only GET or POST requests make it this far
27        # ...
28        pass
29
30Note that request methods should be in uppercase.
31
32.. function:: require_GET()
33
34Decorator to require that a view only accept the GET method.
35
36.. function:: require_POST()
37
38Decorator to require that a view only accept the POST method.
39
40Conditional view processing
41===========================
42
43The following decorators in :mod:`django.views.decorators.http` can be used to
44control caching behavior on particular views.
45
46.. function:: condition(etag_func=None, last_modified_func=None)
47
48.. function:: etag(etag_func)
49
50.. function:: last_modified(last_modified_func)
51
52These decorators can be used to generate ``ETag`` and ``Last-Modified``
53headers; see
54:doc:`conditional view processing </topics/conditional-view-processing>`.
55
56.. module:: django.views.decorators.gzip
57
58GZip compression
59================
60
61The decorators in :mod:`django.views.decorators.gzip` control content
62compression on a per-view basis.
63
64.. function:: gzip_page()
65
66This decorator compresses content if the browser allows gzip compression.
67It sets the ``Vary`` header accordingly, so that caches will base their
68storage on the ``Accept-Encoding`` header.
69
70.. module:: django.views.decorators.vary
71
72Vary headers
73============
74
75The decorators in :mod:`django.views.decorators.vary` can be used to control
76caching based on specific request headers.
77
78.. function:: vary_on_cookie(func)
79
80.. function:: vary_on_headers(*headers)
81
82The ``Vary`` header defines which request headers a cache mechanism should take
83into account when building its cache key.
84
85See :ref:`using vary headers <using-vary-headers>`.