gpt4 book ai didi

python - Django 类型错误 : __init__() takes 1 positional argument but 2 were given

转载 作者:太空宇宙 更新时间:2023-11-03 15:47:05 25 4
gpt4 key购买 nike

我找不到 TypeError 的解决方案:init() takes 1 positional argument but 2 were given

当我尝试在 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)

有什么解决办法吗?

最佳答案

taken = forms.ChoiceField(choices=TAKEN, label='Taken', widget=forms.Select)

你需要把choices放在choices

关于python - Django 类型错误 : __init__() takes 1 positional argument but 2 were given,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49399501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com