WTForms support for input readonly attribute?

casual picture casual · Mar 7, 2012 · Viewed 21.7k times · Source

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?

Answer

Bruno Rocha - rochacbruno picture Bruno Rocha - rochacbruno · Apr 4, 2017

The solution is using render_kw in form field declaration.

my_field = fields.StringField('Label', render_kw={'readonly': True})