首页 > 解决方案 > 将数据从烧瓶 python 传递到 HTML 表单

问题描述

我正在尝试通过GET请求将值传递给 HTML 表单,就像使用 WTForms 一样。我想用一些文本预先填充表单字段。当用户编辑值并单击提交时,新值将在数据库中发布和更新。我应该使用GET请求来做到这一点吗?下面是我正在尝试做的一个示例

 @app.route("/myroute", methods=["GET", "POST"])
def myroute():
if request.method == 'GET':
    request.form['field1'] = 'some text'
    request.form['fields'] = 'some text'

编辑:这就是使用 WTForms 的方式

form = SomeForm()

if request.method == 'GET':

    form.field1.data = 'some text'
    form.field2.data = 'some text'

这可能吗?

标签: pythonhtmlflaskgetflask-wtforms

解决方案


推荐阅读