2014-01-13 72 views
5

當我試圖按照Django Rest框架的快速入門示例時出現錯誤。至於我可以告訴我已經成立了一切,需要的話,我已經看了它幾次,但似乎無法找到錯誤 的錯誤如下django框架快速入門時出現類型錯誤

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 

人看到這是怎麼回事?

+0

你要發佈更多的實際代碼的人來幫助你 – Anentropic

回答

2

變量

self.permission_classes 
在該行

return [permission() for permission in self.permission_classes] 

不返回一個列表。因此你的服務器無法循環它,即「不可迭代」。

17

permission_classesView/ViewSet必須是一個元組

你寫的東西是這樣的:

permission_classes = (permissions.IsAuthenticated) 

忘了一個逗號。

嘗試:

permission_classes = (permissions.IsAuthenticated,) 
+0

還有一個計算器後用類似的錯誤。 [settings.py中的另一個逗號錯誤](https://stackoverflow.com/questions/20519116/typeerror-while-using-django-rest-framework-tutorial) –