Django

Code

Ticket #6832: decor_view_parm_in_urlconf.diff

File decor_view_parm_in_urlconf.diff, 1.1 kB (added by ramiro, 5 months ago)
  • a/docs/url_dispatch.txt

    old new  
    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