【发布时间】:2021-09-24 12:01:45
【问题描述】:
我目前正在 django 中处理表单,并希望在表单中的现有字段中添加另一个字段。原文是:
class NewMessageForm(forms.ModelForm):
class Meta:
model = Message
fields = ['content']
我想添加另一个字段,称为“接收者”。我在想也许我会像这样添加它:
fields = ['content'], ['reciever']
但它给了我一个错误:
文件“C:\Users\Rebecca.Bi\OneDrive - St. Agnes Academy\Desktop\temp newsment\newsment-copy\env\lib\site-packages\django\forms\models.py", 第 190 行,在 if (not exclude or f not in exclude) and f not in ignored TypeError: unhashable type: 'list'
在 forms.py 中添加这个新字段的正确语法是什么?我正在使用 python 3.7
感谢您的帮助 - 一切都很重要!
【问题讨论】:
-
第190行是什么
标签: python python-3.x django forms django-forms