Let me add that the decorator_from_middleware call all the middleware process_* functions if available but these will ofcourse be called at a whole different point in time then the actual middleware. Normally middleware is woven through the whole dispatch process, as a decorator it's wrapped around the view.
On Oct 20, 1:12 pm, Russell Keith-Magee <russ...@keith-magee.com> wrote: > 2010/10/20 Łukasz Rekucki <lreku...@gmail.com>: > > > On 19 October 2010 19:06, Valentin Golev <v.go...@gmail.com> wrote: > >> Hello, > > > 2) decorate the dispatch method. You need to turn login_required into > > a method decorator first (Django should probably provide a tool for > > this). > > Django does :-) It's called method_decorator. > > from django.utils.decorators import method_decorator > > class MyDecoratedView(MyView): > > @method_decorator(login_required) > def dispatch(self, *args, **kwargs): > #... > > This works for any method on any class, that you want to decorate with > any function-based decorator. > > As a point of interest, the django.utils.decorators module has a > couple of other useful utilities in this vein, such as > decorator_from_middleware (which, predictably, enables you to turn any > middleware into a decorator that wraps a single view). > > Yours, > Russ Magee %-) -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.