Is this not a tuple?(这不是元组吗?)
问题描述
我无法弄清楚我在这里做错了什么.我的错误是:/admin/'CategoryAdmin.fields' 的配置不当必须是列表或元组.
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.
CategoryAdmin.fields 不是元组吗?我读错了吗?
Isn't the CategoryAdmin.fields a tuple? Am I reading this wrong?
admin.py..
class CategoryAdmin(admin.ModelAdmin):
fields = ('title')
list_display = ('id', 'title', 'creation_date')
class PostAdmin(admin.ModelAdmin):
fields = ('author', 'title', 'content')
list_display = ('id', 'title', 'creation_date')
admin.site.register(
models.Category,
CategoryAdmin
)
admin.site.register(
models.Post,
PostAdmin
)
推荐答案
不,不是.您需要添加一个逗号:
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',)
括号当然仍然是个好主意,带括号的元组更容易在视觉上发现,并且括号将函数调用中的元组与其他参数(foo(('title',), 'bar')
与 foo('title', 'bar')
) 不同.
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')
).
这篇关于这不是元组吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:这不是元组吗?


基础教程推荐
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 筛选NumPy数组 2022-01-01