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?
给我你的怀抱2017-05-27 17:41:52
The incoming data is 2017-05-25T23:10
,而你的 input_formats=['%m/%d/%YT%H:%M']
,也就是说 input_formats
写错了,正确的应该是 input_formats=['%Y-%m-%dT%H:%M']
.
为情所困2017-05-27 17:41:52
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.
巴扎黑2017-05-27 17:41:52
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.