python - How to verify the input of type="datetime-local" through django form.is_valid()
仅有的幸福
仅有的幸福 2017-05-27 17:39:52
0
3
970

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?

仅有的幸福
仅有的幸福

reply all(3)
给我你的怀抱

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!