Is this not a tuple?

前端 未结 4 650
旧时难觅i
旧时难觅i 2021-01-18 12:35

I can\'t figure out what I\'m doing wrong here. My error is: ImproperlyConfigured at /admin/ \'CategoryAdmin.fields\' must be a list or tuple.

Isn\'

相关标签:
4条回答
  • 2021-01-18 12:51

    It should be:

    fields = ('title', )
    

    Example:

    In [64]: type(('title'))
    Out[64]: str
    
    In [65]: type(('title', ))
    Out[65]: tuple
    
    0 讨论(0)
  • 2021-01-18 12:55

    You need a comma after title:

    fields = ('title',)
    
    0 讨论(0)
  • 2021-01-18 12:58

    No, it is not. You need to add a comma:

    fields = ('title',)
    

    It is the comma that makes this a tuple. The parenthesis are really just optional here:

    >>> ('title')
    'title'
    >>> 'title',
    ('title',)
    

    The parenthesis are of course still a good idea, with parenthesis tuples are easier to spot visually, and the parenthesis distinguish the tuple in a function call from other parameters (foo(('title',), 'bar') is different from foo('title', 'bar')).

    0 讨论(0)
  • 2021-01-18 13:01

    Replace it with this:

    fields = ('title', )
    
    0 讨论(0)
提交回复
热议问题