Python Flask WTForms: How can I disable a field dynamically in a view?

sixarm picture sixarm · May 7, 2013 · Viewed 23.3k times · Source

I've been able to implement this change to create Field which is disabled in WTForms. How would I selectively disable a field in my view before rendering it?

Answer

fengling 姚 picture fengling 姚 · Jan 22, 2017

vim forms.py:

add_time = DateTimeField(

    '添加时间',
    format='%Y-%m-%d %H:%M:%S',
    default=datetime.datetime.now(),
    # I use bs3,and it well add input an attribute disabled
    render_kw={'disabled':''},
    validators=[DataRequired()],
)