Again this topic is now in django-user land. I do this in views.py if want the decorator on all methods (get|post).
myview = login_required(MyView.as_view()) On Dec 7, 2010, at 1:10 PM, Daniel Swarbrick <daniel.swarbr...@gmail.com> wrote: > That is indeed in the docs, and I have seen that. What eludes me is > how to use decorators more complex than login_required() from within > urls.py. > > For example, this works fine: > > from django.contrib.auth.decorators import user_passes_test > from django.utils.decorators import method_decorator > from django.views.generic import TemplateView, View > > class IndexView(TemplateView): > template_name = 'index.html' > > @method_decorator(user_passes_test(lambda u: u.is_superuser)) > def dispatch(self, *args, **kwargs): > return super(IndexView, self).dispatch(*args, **kwargs) > > But how would one avoid having to override the dispatch() method on > many classes, and put the user_passes_test() decorator in the urls.py > definition? Or for that matter, the permission_required() decorator? > > As a side note, could a mixin be used to setup permission_required, > login_required etc, and user-defined class-based views be derived from > multiple parent classes? > > Sorry if this has meandered into django-users land... maybe some > advanced CBV examples in the docs? > > On Dec 7, 6:36 pm, Łukasz Rekucki <lreku...@gmail.com> wrote: >> On 7 December 2010 18:08, Daniel Swarbrick <daniel.swarbr...@gmail.com> >> wrote: >>> Another question (sorry - maybe these should be separate posts), how >>> does one go about using the permission_required() decorator with class- >>> based views, or something like the following: >> >>> @user_passes_test(lambda u: u.is_superuser) >>> def my_superview(request): >>> ... >>> return response >> >> This is in the >> docs:http://docs.djangoproject.com/en/dev/topics/class-based-views/#decora... >> >> PS. As Benjamin already mentioned, I think we're in django-users land now. > > -- > You received this message because you are subscribed to the Google Groups > "Django developers" group. > To post to this group, send email to django-develop...@googlegroups.com. > To unsubscribe from this group, send email to > django-developers+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-developers?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.