我无法找到TypeError的解决方案: init ()需要1个位置参数但是2个被赋予
当我尝试在ubuntu concole中进行迁移时,会出现TypeError。 错误:
File "/home/wojciech/workspace/conference_room/conference_room/conference/forms.py", line 8, in NewRoomForm
taken = forms.ChoiceField(TAKEN, label='Taken', widget=forms.Select)
TypeError: __init__() takes 1 positional argument but 2 were given
形式:
from django import forms
from .models import TAKEN
class NewRoomForm(forms.Form):
name = forms.CharField(label='Name', max_length=32)
number = forms.IntegerField(label='Room Number')
taken = forms.ChoiceField(TAKEN, label='Taken', widget=forms.Select)
description = forms.CharField(label='Description', widget=forms.Textarea)
模型:
TAKEN = (
(True, 'Yes'),
(False, 'No')
)
class Room(models.Model):
name = models.CharField(max_length=32)
number = models.IntegerField()
taken = models.BooleanField(choices=TAKEN)
description = models.CharField(max_length=128)
任何想法如何解决?
答案 0 :(得分:2)
taken = forms.ChoiceField(choices=TAKEN, label='Taken', widget=forms.Select)
您需要将choices
放在choices
键