Ticket #17390: patch_17390.diff

File patch_17390.diff, 1.9 KB (added by Zbigniew Siciarz, 13 years ago)

Mentioned decorating CBVs in the contrib.auth docs.

  • docs/topics/auth.txt

    diff --git a/docs/topics/auth.txt b/docs/topics/auth.txt
    index 1cfccfc..51d0350 100644
    a b The permission_required decorator  
    14571457Limiting access to generic views
    14581458--------------------------------
    14591459
    1460 To limit access to a :doc:`generic view </ref/generic-views>`, write a thin
    1461 wrapper around the view, and point your URLconf to your wrapper instead of the
    1462 generic view itself. For example::
     1460Controlling access to a :doc:`class-based generic view </ref/class-based-views>`
     1461is done by decorating the :meth:`View.dispatch <django.views.generic.base.View.dispatch>`
     1462method on the class. For example::
     1463
     1464    from django.contrib.auth.decorators import login_required
     1465    from django.utils.decorators import method_decorator
     1466    from django.views.generic import TemplateView
     1467
     1468    class ProtectedView(TemplateView):
     1469        template_name = 'secret.html'
     1470
     1471        @method_decorator(login_required)
     1472        def dispatch(self, *args, **kwargs):
     1473            return super(ProtectedView, self).dispatch(*args, **kwargs)
     1474
     1475See :ref:`decorating-class-based-views` for the details.
     1476
     1477Function-based generic views
     1478~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     1479
     1480To limit access to a :doc:`function-based generic view </ref/generic-views>`,
     1481write a thin wrapper around the view, and point your URLconf to your wrapper
     1482instead of the generic view itself. For example::
    14631483
    14641484    from django.views.generic.date_based import object_detail
    14651485
  • docs/topics/class-based-views.txt

    diff --git a/docs/topics/class-based-views.txt b/docs/topics/class-based-views.txt
    index 3812fae..f27a33f 100644
    a b This approach applies the decorator on a per-instance basis. If you  
    584584want every instance of a view to be decorated, you need to take a
    585585different approach.
    586586
     587.. _decorating-class-based-views:
     588
    587589Decorating the class
    588590--------------------
    589591
Back to Top