'type' object is not iterable when I use any decorators

1,087 views
Skip to first unread message

Shekar Tippur

unread,
May 3, 2015, 1:35:45 PM5/3/15
to django...@googlegroups.com
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 iterable
Exception 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']



Vijay Khemlani

unread,
May 3, 2015, 6:27:58 PM5/3/15
to django...@googlegroups.com
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

--
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...@googlegroups.com.
To post to this group, send email to django...@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.

Shekar Tippur

unread,
May 6, 2015, 3:45:42 AM5/6/15
to django...@googlegroups.com
Vijay,

Thanks a lot. That helped.

- Shekar
Reply all
Reply to author
Forward
0 new messages