search

Home  >  Q&A  >  body text

python - How to verify the input of type="datetime-local" through django form.is_valid()

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?

仅有的幸福仅有的幸福2740 days ago985

reply all(3)I'll reply

  • 给我你的怀抱

    给我你的怀抱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'].

    reply
    0
  • 为情所困

    为情所困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.

    reply
    0
  • 巴扎黑

    巴扎黑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.

    reply
    0
  • Cancelreply