I'm getting an error when trying to follow the quickstart example of the Django Rest Framework. As far as i can tell i've set up everything as needed, I've gone over it a couple of times, but can't seem to find the error The error is as follows
Environment:
Request Method: GET
Request URL: http://webdev.lab.unlab.ca/
Django Version: 1.6
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in view
69. return self.dispatch(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/csrf.py" in wrapped_view
57. return view_func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/views.py" in dispatch
399. response = self.handle_exception(exc)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/views.py" in dispatch
387. self.initial(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/views.py" in initial
317. self.check_permissions(request)
File "/usr/local/lib/python2.7/dist-packages/rest_framework/views.py" in check_permissions
273. for permission in self.get_permissions():
File "/usr/local/lib/python2.7/dist-packages/rest_framework/views.py" in get_permissions
226. return [permission() for permission in self.permission_classes]
Exception Type: TypeError at /
Exception Value: 'type' object is not iterable
anyone see what's going on?
The permission_classes
in your View/ViewSet
must be a tuple
You wrote something like this:
permission_classes = (permissions.IsAuthenticated)
forgetting a comma.
try with:
permission_classes = (permissions.IsAuthenticated,)
The variable
self.permission_classes
in the line:
return [permission() for permission in self.permission_classes]
does not return a list. And therefore your server is unable to loop over it, i.e. "not iterable".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With