![](/img/trans.png)
[英]TypeError: “__init__() got multiple values for keyword argument 'name'”
[英]TypeError: __init__() got multiple values for keyword argument 'choices'
class StatisticsBaseForm(forms.Form):
type_choice = forms.ChoiceField(_("Type"), choices=settings.STATISTICS_TYPE_CHOICES, default=0)
period = forms.ChoiceField("Period", max_length=20, choices=settings.PERIODS, default='week')
def __init__(self, *args, **kwargs):
super(StatisticsBaseForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
class Meta:
model = Statistics
fields = '__all__'
追溯如下
File "/home/jeremie/Projects/Work_Projects/django/loanwolf/statistics/urls.py", line 6, in <module>
from loanwolf.statistics.views import StatisticsIndexView
File "/home/jeremie/Projects/Work_Projects/django/loanwolf/statistics/views.py", line 8, in <module>
from loanwolf.statistics.forms import StatisticsBaseForm
File "/home/jeremie/Projects/Work_Projects/django/loanwolf/statistics/forms.py", line 17, in <module>
class StatisticsBaseForm(forms.Form):
File "/home/jeremie/Projects/Work_Projects/django/loanwolf/statistics/forms.py", line 18, in StatisticsBaseForm
type_choice = forms.ChoiceField(_("Type"), choices=settings.STATISTICS_TYPE_CHOICES, default=0)
TypeError: __init__() got multiple values for keyword argument 'choices'
我有此错误,但我没有设法解决。 我该如何处理错误? 最初, StatisticsBaseForm
是一个forms.ModelForm
, type_choice
和period
在我的Statistics模型中,两者均为SmallIntegerfield
。 在这种特定情况下,一切工作正常。
改成
type_choice = forms.ChoiceField(label=_("Type"), choices=settings.STATISTICS_TYPE_CHOICES, initial=0)
period = forms.ChoiceField(label="Period", choices=settings.PERIODS, initial='week')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.