user_passes_test is for decorating functions, not classes
Django Rest Framework has its own system for permissions (and you seem to be already using it)
Use that instead I think
On Sun, May 3, 2015 at 2:35 PM, Shekar Tippur <ctippur@gmail.com> wrote:
Hello,--Here is a decorator that I am trying ot use to restrict access to the class to only super users: Can someone please point me to what could be wrong. If I take the decorator, I am able to get thro but it is not restricted to only super users.@user_passes_test(lambda u: u.is_superuser)
class UserViewSet(viewsets.ModelViewSet):
permission_classes = [permissions.TokenHasReadWriteScope]
queryset = User.objects.all()
serializer_class = UserSerializer
model=User
When I use this, I get the error:
'type' object is not iterable
TypeError at /users/
'type' object is not iterable
Request Method: GET Request URL: http://127.0.0.1:8000/users/ Django Version: 1.8 Exception Type: TypeError Exception Value: 'type' object is not iterableException Location: /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/rest_framework/views.py in get_permissions, line 252 Python Executable: /Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 Python Version: 3.4.3 Python Path: ['/Users/PycharmProjects/screens', '/Users/PycharmProjects/screens', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python34.zip', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages']
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ee405db3-8ace-4f10-8bc3-a72b81ed9fc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALn3ei3jSsyToc9eQjkOYK4BS9LTUgw_SFhQmBHif10POq%2BvKw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment