Code

Ticket #6832: decor_view_parm_in_urlconf.diff

File decor_view_parm_in_urlconf.diff, 1.1 KB (added by ramiro, 6 years ago)
Line 
1diff -r 04db33c299a1 docs/url_dispatch.txt
2--- a/docs/url_dispatch.txt     Wed Mar 19 01:04:19 2008 -0300
3+++ b/docs/url_dispatch.txt     Wed Mar 19 11:24:11 2008 -0300
4@@ -528,6 +528,24 @@ Note that if you use this technique -- p
5 Note that if you use this technique -- passing objects rather than strings --
6 the view prefix (as explained in "The view prefix" above) will have no effect.
7 
8+One useful application of the callable object syntax can be seen when using
9+decorators; this allows you to apply decorators to views *in your URLconf*::
10+
11+    from django.conf.urls.defaults import *
12+    from django.contrib.auth.decorators import login_required
13+    from django.views.decorators.cache import cache_page
14+    from mysite.views import archive, about, contact
15+
16+    urlpatterns = patterns('',
17+        (r'^archive/$', login_required(archive)),
18+        (r'^about/$', cache_page(about, 600)),
19+        (r'^contact/$', contact),
20+    )
21+
22+Note that in this case you can't use the string syntax to specify the view
23+parameter to the decorator itself, you must use the callable object
24+syntax.
25+
26 Naming URL patterns
27 ===================
28