如何用Flask处理希登菲尔德?

2024-09-30 20:33:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我很难理解在这种情况下如何使用隐藏形式,或者即使我应该使用这种技术。 我的主页all_products.html将有一个产品列表,每个产品都有一个按钮形式的链接,可以查看该产品的更多详细信息:

<form action="" method="post" name="editer">
    {{ form1.prodid(value="car") }}
    {{ form1.prodyear(value="2012") }}
    <a href="{{ url_for('edit_product', product='car') }}">
        <input type="button" value="Edit" />
    </a><br>
</form>
<form action="" method="post" name="editer">
    {{ form2.prodid(value="truck") }}
    {{ form2.prodyear(value="1999") }}
    <a href="{{ url_for('edit_product', product='truck') }}">
        <input type="button" value="Edit" />
    </a><br>
</form>

模板是用

^{pr2}$

所有产品的形式是:

class AllProductsForm(Form):
    prodid = HiddenField('myfield')
    prodyear = HiddenField('myfield')

编辑_产品.html模板使用:

@app.route('/productedit/<product>', methods=['GET', 'POST'])
def edit_product(product):
    form =  AllProductsForm()
    print form.prodid.data
    return render_template('edit_product.html')

这似乎不是我想要的。我希望edit_product()能够访问包含单击按钮的数据的表单,但它是空的。在

我还有别的办法吗?在真正的版本中,我不会只有2个产品,而是很多是循环通过。在


Tags: nameform产品valuehtmlactionproductpost