2010/10/20 Łukasz Rekucki <[email protected]>:
> On 19 October 2010 19:06, Valentin Golev <[email protected]> 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 [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-users?hl=en.

Reply via email to