#13409: "wrap" argument for django.conf.urls.defaults.url to decorate views more
easily
----------------------------------------------------------------+-----------
Reporter: yourcelf | Owner:
nobody
Status: new | Milestone:
Component: Core framework | Version:
SVN
Keywords: url, RegexURLResolver, RegexURLPattern, decorators | Stage:
Unreviewed
Has_patch: 1 |
----------------------------------------------------------------+-----------
The [http://docs.djangoproject.com/en/dev/topics/cache/#specifying-per-
view-cache-in-the-urlconf documention for cacheing] recommends a method
for using cache decorators in the urlconf, which is a natural way to do
page-based cacheing. However, most urlconfs of any complexity use string
representations of views (and perhaps also the "prefix" feature of
patterns()). To decorate the views, one would have to import them all
explicitly and then apply the wrapper functions, which is cumbersome.
The attached patch addresses this by adding a "wrap" function to url(),
which specifies a function or list of functions with which to "decorate"
the view. For includes, the wrap argument applies to all included URLs.
It can be used like this:
{{{
urlpatterns = patterns('myapp.views',
url(r'^pattern/$', 'viewfunc', wrap=mydecorator),
url(r'^pattern2/$', include('otherapp.urls'), wrap=[mydecorator1,
mydecorator2]),
)
}}}
This can provide a natural way to add cacheing or any other decoration
(such as login_required) both to individual views, or to all the views
within an include.
--
Ticket URL: <http://code.djangoproject.com/ticket/13409>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.