Ticket #6181: http-view-decorators.diff

File http-view-decorators.diff, 3.1 KB (added by Adam Vandenberg, 14 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>`
    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>`
    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
    - +  
     2View Decorators
     5.. module:: django.views.decorators.http
     7The decorators in the ``django.views.decorators.http`` module can be applied
     8to views to process certain HTTP headers.
     15.. function:: require_http_methods(request_method_list)
     17This decorator to make a view only accept particular request methods.
     19    from django.views.decorators.http import require_http_methods
     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        # ...
     26Note that request methods should be in uppercase.
     28Two shorcuts are defined, ``require_GET`` and ``require_POST``, which limit
     29the request method to GET and POST respectively.
     34.. function:: condition(etag_func=None, last_modified_func=None)
     36The ``condition`` decorator support conditional retrieval for a view
     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).
     45If both parameters are provided, all the preconditions must be met before
     46the view is processed.
     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.
     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
     56Two shortcuts are defined for the common cases.
     58.. function:: etag(etag_func)
     60This decorator provides only an etag function.
     62.. function:: last_modified(last_modified_func)
     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:  
    1111   file-uploads
    1212   shortcuts
     13   decorators
    1314   generic-views
    1415   middleware
    1516   sessions
Back to Top