TemplateView compatible with permission_required decorator?

134 views
Skip to first unread message

Victor Hooi

unread,
Oct 5, 2011, 10:27:31 AM10/5/11
to django...@googlegroups.com
Hi,

I'm attempting to use one of the new class-based TemplateView with the permission_required decorator:

@permission_required('foo.count_peas')
class Pea(TemplateView):
    template_name = "pea.html"

However, when I do that, I get an error:

Exception Type: AttributeError at /someurl/
Exception Value: 'function' object has no attribute 'as_view'

If I comment out the permission_required decorator, the view seems to work fine.

Are the new class-based views compatible with the permission_required decorator?

Or is there something I need to do to make them work together.

Cheers,
Victor

Dan Gentry

unread,
Oct 5, 2011, 2:04:07 PM10/5/11
to Django users
Instead, you should decorate the dispatch method in the class-based
view. See the docs here:

https://docs.djangoproject.com/en/dev/topics/class-based-views/#decorating-the-class
Reply all
Reply to author
Forward
0 new messages