Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type error with django framework quickstart

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?

like image 683
loogie Avatar asked Jan 13 '14 15:01

loogie


2 Answers

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,)
like image 78
Andrea de Marco Avatar answered Nov 11 '22 09:11

Andrea de Marco


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".

like image 36
Joseph Victor Zammit Avatar answered Nov 11 '22 08:11

Joseph Victor Zammit