mirror of
https://github.com/django/django.git
synced 2024-12-01 15:42:04 +01:00
Fixed #15395 -- Documented the modules/import paths for the various decorators in django.views.decorators
. Thanks to slinkp for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15671 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
70d3c84d18
commit
c9db8cc83f
@ -2,7 +2,7 @@
|
|||||||
View decorators
|
View decorators
|
||||||
===============
|
===============
|
||||||
|
|
||||||
.. currentmodule:: django.views.decorators.http
|
.. module:: django.views.decorators.http
|
||||||
|
|
||||||
Django provides several decorators that can be applied to views to support
|
Django provides several decorators that can be applied to views to support
|
||||||
various HTTP features.
|
various HTTP features.
|
||||||
@ -10,12 +10,16 @@ various HTTP features.
|
|||||||
Allowed HTTP methods
|
Allowed HTTP methods
|
||||||
====================
|
====================
|
||||||
|
|
||||||
|
The following decorators in :mod:`django.views.decorators.http` can be used to
|
||||||
|
restrict access to views based on the request method.
|
||||||
|
|
||||||
.. function:: require_http_methods(request_method_list)
|
.. function:: require_http_methods(request_method_list)
|
||||||
|
|
||||||
This decorator is used to make a view only accept particular request methods.
|
This decorator is used to ensure that a view only accepts particular request
|
||||||
Usage::
|
methods. Usage::
|
||||||
|
|
||||||
from django.views.decorators.http import require_http_methods
|
from django.views.decorators.http import require_http_methods
|
||||||
|
|
||||||
@require_http_methods(["GET", "POST"])
|
@require_http_methods(["GET", "POST"])
|
||||||
def my_view(request):
|
def my_view(request):
|
||||||
# I can assume now that only GET or POST requests make it this far
|
# I can assume now that only GET or POST requests make it this far
|
||||||
@ -35,6 +39,9 @@ Decorator to require that a view only accept the POST method.
|
|||||||
Conditional view processing
|
Conditional view processing
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
The following decorators in :mod:`django.views.decorators.http` can be used to
|
||||||
|
control caching behavior on particular views.
|
||||||
|
|
||||||
.. function:: condition(etag_func=None, last_modified_func=None)
|
.. function:: condition(etag_func=None, last_modified_func=None)
|
||||||
|
|
||||||
.. function:: etag(etag_func)
|
.. function:: etag(etag_func)
|
||||||
@ -45,27 +52,33 @@ These decorators can be used to generate ``ETag`` and ``Last-Modified``
|
|||||||
headers; see
|
headers; see
|
||||||
:doc:`conditional view processing </topics/conditional-view-processing>`.
|
:doc:`conditional view processing </topics/conditional-view-processing>`.
|
||||||
|
|
||||||
.. currentmodule:: django.views.decorators.gzip
|
.. module:: django.views.decorators.gzip
|
||||||
|
|
||||||
GZip compression
|
GZip compression
|
||||||
================
|
================
|
||||||
|
|
||||||
|
The decorators in :mod:`django.views.decorators.gzip` control content
|
||||||
|
compression on a per-view basis.
|
||||||
|
|
||||||
.. function:: gzip_page()
|
.. function:: gzip_page()
|
||||||
|
|
||||||
This decorator compresses content if the browser allows gzip compression.
|
This decorator compresses content if the browser allows gzip compression.
|
||||||
It sets the ``Vary`` header accordingly, so that caches will base their
|
It sets the ``Vary`` header accordingly, so that caches will base their
|
||||||
storage on the ``Accept-Encoding`` header.
|
storage on the ``Accept-Encoding`` header.
|
||||||
|
|
||||||
.. currentmodule:: django.views.decorators.vary
|
.. module:: django.views.decorators.vary
|
||||||
|
|
||||||
Vary headers
|
Vary headers
|
||||||
============
|
============
|
||||||
|
|
||||||
The ``Vary`` header defines which request headers a cache mechanism should take
|
The decorators in :mod:`django.views.decorators.vary` can be used to control
|
||||||
into account when building its cache key.
|
caching based on specific request headers.
|
||||||
|
|
||||||
.. function:: vary_on_cookie(func)
|
.. function:: vary_on_cookie(func)
|
||||||
|
|
||||||
.. function:: vary_on_headers(*headers)
|
.. function:: vary_on_headers(*headers)
|
||||||
|
|
||||||
|
The ``Vary`` header defines which request headers a cache mechanism should take
|
||||||
|
into account when building its cache key.
|
||||||
|
|
||||||
See :ref:`using vary headers <using-vary-headers>`.
|
See :ref:`using vary headers <using-vary-headers>`.
|
||||||
|
Loading…
Reference in New Issue
Block a user