WTForms support for input readonly attribute?

前端 未结 4 1742
伪装坚强ぢ
伪装坚强ぢ 2021-02-04 02:14

Here they say it\'s not supported out of the box.

Do you know a way to make HTML input form fields use the \'readonly\' attribute with WTForms?

4条回答
  •  深忆病人
    2021-02-04 02:42

    https://wtforms-components.readthedocs.org/en/latest/#

    from wtforms import Form, DateField, TextField
    from wtforms_components import TimeField, read_only
    
    class EventForm(Form):
        name = TextField('Name')
        start_date = DateField('Start date')
        start_time = TimeField('Start time')
    
        def __init__(self, *args, **kwargs):
            super(EventForm, self).__init__(*args, **kwargs)
            read_only(self.name)
    

提交回复
热议问题