Ticket #6181: http-view-decorators.diff

File http-view-decorators.diff, 3.1 KB (added by Adam Vandenberg, 9 years ago)
  • docs/index.txt

    diff --git a/docs/index.txt b/docs/index.txt
    index 55e6cda..11cbe47 100644
    a b The view layer 
    9393      :doc:`View functions <topics/http/views>` |
    9494      :doc:`Shortcuts <topics/http/shortcuts>`
    9595
    96     * **Reference:**  :doc:`Request/response objects <ref/request-response>`
     96    * **HTTP:**
     97      :doc:`Request/response objects <ref/request-response>` |
     98      :doc:`Decorators <topics/http/decorators>`
    9799
    98100    * **File uploads:**
    99101      :doc:`Overview <topics/http/file-uploads>` |
  • new file docs/topics/http/decorators.txt

    diff --git a/docs/topics/http/decorators.txt b/docs/topics/http/decorators.txt
    new file mode 100644
    index 0000000..f5cc2f1
    - +  
     1===============
     2View Decorators
     3===============
     4
     5.. module:: django.views.decorators.http
     6
     7The decorators in the ``django.views.decorators.http`` module can be applied
     8to views to process certain HTTP headers.
     9
     10
     11
     12``require_http_methods``
     13========================
     14
     15.. function:: require_http_methods(request_method_list)
     16
     17This decorator to make a view only accept particular request methods.
     18Usage::
     19    from django.views.decorators.http import require_http_methods
     20
     21    @require_http_methods(["GET", "POST"])
     22    def my_view(request):
     23        # I can assume now that only GET or POST requests make it this far
     24        # ...
     25
     26Note that request methods should be in uppercase.
     27
     28Two shorcuts are defined, ``require_GET`` and ``require_POST``, which limit
     29the request method to GET and POST respectively.
     30
     31``condition``
     32=============
     33
     34.. function:: condition(etag_func=None, last_modified_func=None)
     35
     36The ``condition`` decorator support conditional retrieval for a view
     37function.
     38
     39The parameters are callables to compute the ETag and last modified time for
     40the requested resource, respectively. The callables are passed the same
     41parameters as the view itself. The Etag function should return a string (or
     42None if the resource doesn't exist), whilst the last_modified function
     43should return a datetime object (or None if the resource doesn't exist).
     44
     45If both parameters are provided, all the preconditions must be met before
     46the view is processed.
     47
     48This decorator will either pass control to the wrapped view function or
     49return an HTTP 304 response (unmodified) or 412 response (preconditions
     50failed), depending upon the request method.
     51
     52Any behavior marked as "undefined" in the HTTP spec (e.g. ``If-none-match``
     53plus ``If-modified-since`` headers) will result in the view function being
     54called.
     55
     56Two shortcuts are defined for the common cases.
     57
     58.. function:: etag(etag_func)
     59
     60This decorator provides only an etag function.
     61
     62.. function:: last_modified(last_modified_func)
     63
     64This decorator provides only a last-modified function.
  • docs/topics/http/index.txt

    diff --git a/docs/topics/http/index.txt b/docs/topics/http/index.txt
    index 5ef776d..83c73b2 100644
    a b Information on handling HTTP requests in Django: 
    1010   views
    1111   file-uploads
    1212   shortcuts
     13   decorators
    1314   generic-views
    1415   middleware
    1516   sessions
Back to Top