wtforms, CSRF, flask, FieldList

前端 未结 4 1421
陌清茗
陌清茗 2020-12-10 12:14

I\'m having trouble passing through validation when using a FieldList with WTForms. I keep getting this error. {\'csrf_token\': [u\'CSRF token missing\'

4条回答
  •  情书的邮戳
    2020-12-10 12:30

    The issue seems to be that Flask-WTForms Form is actually a subclass of wtforms.ext.SecureForm - and the only way to disable the csrf protection on a form is to pass the keyword argument csrf_enabled=False to the form when constructing it. Since FormField actually handles instantiating the form and you can either:

    • Create a subclass of FormField that will let you pass in form keyword arguments
      or
    • Subclass wtforms.Form rather than flask.ext.wtforms.Form for your FilterForm (as long as you never display a FilterForm on its own you won't need to worry about CSRF).

提交回复
热议问题