TypeError:__ init __()为关键字参数'choices'

时间:2017-09-15 10:57:44

标签: python django

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'

我有这个错误,但我没有设法解决它。我怎么能继续犯这个错误?开始时,StatisticsBaseFormforms.ModelFormtype_choiceperiod位于我的统计模型中,两者均为SmallIntegerfield。在这个特定的背景下,一切都很好。

1 个答案:

答案 0 :(得分:1)

更改为

type_choice = forms.ChoiceField(label=_("Type"), choices=settings.STATISTICS_TYPE_CHOICES, initial=0)
period = forms.ChoiceField(label="Period", choices=settings.PERIODS, initial='week')