Ticket #6832: decor_view_parm_in_urlconf.diff

File decor_view_parm_in_urlconf.diff, 1.1 KB (added by Ramiro Morales, 10 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.
     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*::
     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
     539    urlpatterns = patterns('',
     540        (r'^archive/$', login_required(archive)),
     541        (r'^about/$', cache_page(about, 600)),
     542        (r'^contact/$', contact),
     543    )
     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
    531549Naming URL patterns
Back to Top