Disabled field is considered for validation in WTForms and Flask

后端 未结 4 776
别跟我提以往
别跟我提以往 2021-02-01 08:38

I have some fields in page disabled as for example:(using jinja2 templating system)



{{ form.na
4条回答
  •  孤街浪徒
    2021-02-01 09:05

    You need to make the name field optional when defining the form.

    name = wtf.TextField("Team Name", validators=[validators.Optional()])
    

    Then in your views, pass a variable called "role" and set it to either manager or admin depending on the user.

    
    {% if role == 'manager' % }
        {{ form.name(disabled=True) }}
    {% else % }
        {{ form.name() }}
    {{ form.title }}
    -- submit button --
    
    

提交回复
热议问题