PageRenderTime 23ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): BSD-3-Clause
  1. ===============
  2. View decorators
  3. ===============
  4. .. module:: django.views.decorators.http
  5. Django provides several decorators that can be applied to views to support
  6. various HTTP features.
  7. Allowed HTTP methods
  8. ====================
  9. The decorators in :mod:`django.views.decorators.http` can be used to restrict
  10. access to views based on the request method. These decorators will return
  11. a :class:`django.http.HttpResponseNotAllowed` if the conditions are not met.
  12. .. function:: require_http_methods(request_method_list)
  13. This decorator is used to ensure that a view only accepts particular request
  14. methods. Usage::
  15. from django.views.decorators.http import require_http_methods
  16. @require_http_methods(["GET", "POST"])
  17. def my_view(request):
  18. # I can assume now that only GET or POST requests make it this far
  19. # ...
  20. pass
  21. Note that request methods should be in uppercase.
  22. .. function:: require_GET()
  23. Decorator to require that a view only accept the GET method.
  24. .. function:: require_POST()
  25. Decorator to require that a view only accept the POST method.
  26. Conditional view processing
  27. ===========================
  28. The following decorators in :mod:`django.views.decorators.http` can be used to
  29. control caching behavior on particular views.
  30. .. function:: condition(etag_func=None, last_modified_func=None)
  31. .. function:: etag(etag_func)
  32. .. function:: last_modified(last_modified_func)
  33. These decorators can be used to generate ``ETag`` and ``Last-Modified``
  34. headers; see
  35. :doc:`conditional view processing </topics/conditional-view-processing>`.
  36. .. module:: django.views.decorators.gzip
  37. GZip compression
  38. ================
  39. The decorators in :mod:`django.views.decorators.gzip` control content
  40. compression on a per-view basis.
  41. .. function:: gzip_page()
  42. This decorator compresses content if the browser allows gzip compression.
  43. It sets the ``Vary`` header accordingly, so that caches will base their
  44. storage on the ``Accept-Encoding`` header.
  45. .. module:: django.views.decorators.vary
  46. Vary headers
  47. ============
  48. The decorators in :mod:`django.views.decorators.vary` can be used to control
  49. caching based on specific request headers.
  50. .. function:: vary_on_cookie(func)
  51. .. function:: vary_on_headers(*headers)
  52. The ``Vary`` header defines which request headers a cache mechanism should take
  53. into account when building its cache key.
  54. See :ref:`using vary headers <using-vary-headers>`.