Django错误`fields`选项必须是列表或元组或"__all__"

The*_*e87 1 django

TypeError at /api/team/
The `fields` option must be a list or tuple or "__all__". Got str.
Request Method: GET
Request URL:    http://127.0.0.1:8000/api/team/
Django Version: 1.9
Exception Type: TypeError
Exception Value:    
The `fields` option must be a list or tuple or "__all__". Got str.
Exception Location: /Library/Python/2.7/site-packages/rest_framework/serializers.py in get_field_names, line 971
Python Executable:  /usr/bin/python
Python Version: 2.7.10
Python Path:    
['/Desktop/webprog/python/wsgi/openshift',
 '/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg',
 '/Library/Python/2.7/site-packages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC']
Server time:    Mon, 28 Mar 2016 14:42:11 +0000
Run Code Online (Sandbox Code Playgroud)

这个错误意味着什么,它发生在哪里?它说Exception Location但是在rest_framework中...但是错误显然在我的代码中,我怎么能找到?:S

serializers.py

from api.models import Team
from rest_framework import serializers

class TeamSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Team
        fields = ('name')
Run Code Online (Sandbox Code Playgroud)

oro*_*aki 12

你只需要改变这个:

fields = ('name')
Run Code Online (Sandbox Code Playgroud)

对此:

fields = ('name',)
Run Code Online (Sandbox Code Playgroud)

请注意逗号.只有一个对象的元组需要一个尾随逗号来区分它与带括号的对象.