Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Error The `fields` option must be a list or tuple or "__all__"

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

What does this error mean and where does it occur? It says Exception Location but that is within the rest_framework...but the error is obviously within my code, how can I find out? :S

serializers.py

from api.models import Team
from rest_framework import serializers

class TeamSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Team
        fields = ('name')
like image 386
TheRapture87 Avatar asked Mar 28 '16 14:03

TheRapture87


1 Answers

You just need to change this:

fields = ('name')

to this:

fields = ('name',)

Note the comma. A tuple with only one object requires a trailing comma to distinguish it from a parenthesized object.

like image 67
orokusaki Avatar answered Oct 06 '22 02:10

orokusaki