Form is never valid with WTForms

前端 未结 1 1414
情深已故
情深已故 2020-11-30 15:49

I have a Flask-WTF form for sign in. Apparently the form is never valid, no matter what I enter \"success\" is never printed. Why isn\'t my form validating?



        
1条回答
  •  借酒劲吻你
    2020-11-30 16:08

    Flask-WTF adds a CSRF protection field. If it's not present, the CSRF validation will fail, and the form will be invalid. Use form.hidden_tag() to include any hidden fields in your form (including the CSRF field).

    {{ form.hidden_tag() }} ...

    In general, if a form is not validating, you should check form.errors after calling validate to see what's wrong.

    You don't see the error since you're not rendering that field (or rendering the errors for any fields in this case, but that wouldn't help with this issue). If you ran in a debugger and examined form.errors, you would see that there was indeed a "CSRF token missing" error.

    0 讨论(0)
提交回复
热议问题