简体   繁体   English

TypeError:__init __()为关键字参数“ choices”获得了多个值

[英]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__'

The traceback is the following 追溯如下

  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'

I have this error, but I didn't manage to fix it. 我有此错误,但我没有设法解决。 How could I go ahead on the error? 我该如何处理错误? At the beginning, StatisticsBaseForm was a forms.ModelForm , and type_choice and period was in my Statistics model where both were SmallIntegerfield . 最初, StatisticsBaseForm是一个forms.ModelFormtype_choiceperiod在我的Statistics模型中,两者均为SmallIntegerfield In that specific context, everything worked fine. 在这种特定情况下,一切工作正常。

Change to 改成

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.

相关问题 TypeError:“ __ init __()为关键字参数&#39;name&#39;获得了多个值” - TypeError: “__init__() got multiple values for keyword argument 'name'” TypeError:__ init __()得到关键字参数&#39;customer&#39;的多个值 - TypeError: __init__() got multiple values for keyword argument 'customer' TypeError: __init__() 得到了一个意外的关键字参数“选择” - TypeError: __init__() got an unexpected keyword argument 'choices' 在Scrapy中使用规则和请求会引发异常TypeError:__init __()为关键字参数&#39;callback&#39;获得了多个值 - Using Rules and Requests in Scrapy throws exception TypeError: __init__() got multiple values for keyword argument 'callback' / __init __()的Django Rest Framework TypeError为关键字参数&#39;read_only&#39;获取了多个值 - Django Rest Framework TypeError at / __init__() got multiple values for keyword argument 'read_only' TypeError at &#39;&#39; __init__() 得到一个意外的关键字参数 &#39;&#39; - TypeError at '' __init__() got an unexpected keyword argument '' TypeError: __init__() 在 python 的 argparser 中得到了一个意外的关键字参数 'choices' - TypeError: __init__() got an unexpected keyword argument 'choices' in python's argparser windrose:__init __()获得了多个关键字参数值 - windrose: __init__() got multiple values for keyword argument __init __()为关键字参数“ bar”获得了多个值 - __init__() got multiple values for keyword argument 'bar' __init __()为关键字参数&#39;input_formats&#39;获得了多个值 - __init__() got multiple values for keyword argument 'input_formats'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM