[英]__init__() got multiple values for keyword argument 'input_formats'
forms.py forms.py
from django import forms
ACCEPTED_FORMATS = ['%d-%m-%Y', '%d.%m.%Y', '%d/%m/%Y']
class LeaveRequestForm(forms.Form):
start_date = forms.DateField(input_formats=ACCEPTED_FORMATS)
end_date = forms.DateField(input_formats=ACCEPTED_FORMATS)
working_days = forms.IntegerField(min_value=1)
I couldn't find any date format that could pass form validation, every time I received 'Enter a valid date.', so when I tried to define some the exception came out: 每当我收到“输入有效日期”时,我都找不到任何可以通过表单验证的日期格式,因此,当我尝试定义一些日期格式时,出现了异常:
__init__() got multiple values for keyword argument 'input_formats'
https://docs.djangoproject.com/en/1.8/ref/forms/fields/#datefield https://docs.djangoproject.com/en/1.8/ref/forms/fields/#datefield
settings.py settings.py
... ...
USE_I18N = True
USE_L10N = True
... ...
I also tried built-in SelectDateWidget with no luck, every time produced invalid date. 我还尝试了内置的SelectDateWidget,但每次运出无效的日期时都没有运气。 Maybe there is some "cache" issue: "Enter a valid date" Error in Django Forms DateField
也许存在一些“缓存”问题: Django Forms DateField中的“输入有效日期”错误
What should I do to get past this validation checks and move on with proper dates? 我应该怎么做才能通过此验证检查并继续正确的日期? Are the docs missing something with an error I encountered?
文档是否缺少我遇到的错误?
input_formats is not a kwarg, it's the sole option to DateField. input_formats不是垃圾,它是DateField的唯一选项。 Drop the
input_formats=
删除
input_formats=
ACCEPTED_FORMATS = ['%d-%m-%Y', '%d.%m.%Y', '%d/%m/%Y']
class LeaveRequestForm(forms.Form):
start_date = forms.DateField(ACCEPTED_FORMATS)
end_date = forms.DateField(ACCEPTED_FORMATS)
working_days = forms.IntegerField(min_value=1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.