"wrap" argument for django.conf.urls.defaults.url to decorate views more easily
|Reported by:||Charlie DeTar||Owned by:||nobody|
|Severity:||Normal||Keywords:||url, RegexURLResolver, RegexURLPattern, decorators|
|Cc:||chazen@…, erob@…, Florian.Sening@…||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||yes||Patch needs improvement:||no|
The 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.
Change History (11)
comment:1 Changed 7 years ago by
|Triage Stage:||Unreviewed → Design decision needed|