django.utils.decorators.decorator_from_middleware doesn't work with parameters
|Reported by:||eugene@…||Owned by:||adrian|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||yes||Patch needs improvement:||no|
django.utils.decorators.decorator_from_middleware doesn't work for decorators with parameters:
- Any parameter of decorator causes a call to _decorator_from_middleware().
- Instead of actual wrapping _wrapped_view() is called, which fails because at that point request is actually a view function.
Basically this works:
@cache_page def my_cool_view(request): # cool processing
@cache_page(60) def my_cool_view(request): # cool processing
@cache_page(cache_timeout=60) def my_cool_view(request): # cool processing
Just try it.
If this is an intended behavior, we need to update documentation for @cache_page. (I didn't check if there is a documentation for @gzip_page and @conditional_page).
It makes sense to document that per-page caching still uses CACHE_MIDDLEWARE_SECONDS and CACHE_MIDDLEWARE_KEY_PREFIX, if no decorator arguments were given. And currently it is impossible to specify them.
Change History (15)
Changed 8 years ago by anonymous
comment:4 Changed 8 years ago by anonymous
- Component changed from Documentation to Uncategorized
- Has patch set
- Needs tests set
- Patch needs improvement set
comment:6 Changed 8 years ago by Gary Wilson <gary.wilson@…>
- Component changed from Uncategorized to Tools
- Keywords cache_page added
- Owner changed from jacob to adrian
Changed 8 years ago by Gary Wilson <gary.wilson@…>
comment:12 Changed 8 years ago by mtredinnick
- Resolution set to fixed
- Status changed from new to closed