forms.py:
select_time = forms.DateTimeField(
label='时间',
input_formats=['%m/%d/%YT%H:%M'],
widget=forms.DateTimeInput(attrs={
'class': 'weui-input',
'type': 'datetime-local',
'emptyTips': '请选择时间'
})
)
In the above form, the time format passed is 2017-05-25T23:10
, which cannot pass the form.is_valid()
verification. How to deal with it?
The incoming data is
2017-05-25T23:10
,而你的input_formats=['%m/%d/%YT%H:%M']
,也就是说input_formats
写错了,正确的应该是input_formats=['%Y-%m-%dT%H:%M']
.The format defined in your form is
%m/%d/%YT%H:%M
但是你传的却是2017-05-25T23:10
Of course it cannot pass the verification. You need to modify the format definition in the form.According to the strftime(format) method, the input_formats format you want should be
%Y-%M-%D/T%H:%M
For the strftime(format) method, see the first table in document 8.1.8. This format comes from the C language and is quite common.