Using WTForms' populate_obj( ) method with Flask micro framework

怎甘沉沦 提交于 2019-12-04 05:27:34

UserForm should have request.form passed into it to populate it with the values available in the POST request (if any).

form = UserForm(request.form, obj=user)

Are you using Flask-WTF? If so, check out the following sample code:

https://github.com/sean-/flask-skeleton/blob/master/skeleton/modules/aaa/views.py#L13

Specifically, you would:

def edit():
    form = UserForm()
    if form.validate_on_submit():
        # Commit your form data

Bottom line, if you're using Flask-WTF, I'm not sure what your question is. If you aren't using Flask-WTF, use Flask-WTF.

In case of Flask-WTF, you can write like

form = UserForm(obj=user)

Thant will work!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!