Ticket #6832: decor_view_parm_in_urlconf.diff

File decor_view_parm_in_urlconf.diff, 1.1 KB (added by Ramiro Morales, 16 years ago)
  • docs/url_dispatch.txt

    diff -r 04db33c299a1 docs/url_dispatch.txt
    a b Note that if you use this technique -- p  
    528528Note that if you use this technique -- passing objects rather than strings --
    529529the view prefix (as explained in "The view prefix" above) will have no effect.
    530530
     531One useful application of the callable object syntax can be seen when using
     532decorators; this allows you to apply decorators to views *in your URLconf*::
     533
     534    from django.conf.urls.defaults import *
     535    from django.contrib.auth.decorators import login_required
     536    from django.views.decorators.cache import cache_page
     537    from mysite.views import archive, about, contact
     538
     539    urlpatterns = patterns('',
     540        (r'^archive/$', login_required(archive)),
     541        (r'^about/$', cache_page(about, 600)),
     542        (r'^contact/$', contact),
     543    )
     544
     545Note that in this case you can't use the string syntax to specify the view
     546parameter to the decorator itself, you must use the callable object
     547syntax.
     548
    531549Naming URL patterns
    532550===================
    533551
Back to Top