Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flask:从一页到另一页的隐藏值_Flask_Hidden Field_Flask Wtforms - Fatal编程技术网

Flask:从一页到另一页的隐藏值

Flask:从一页到另一页的隐藏值,flask,hidden-field,flask-wtforms,Flask,Hidden Field,Flask Wtforms,我读了其他的问题,但还是不知道出了什么问题。 我想将一个隐藏值从一个页面:dashboard传递到另一个页面:seegoodsrec 希望有人能帮忙。 我使用此表单获取一个隐藏值: class customerIDForm(Form): customerID = HiddenField() 然后在我的仪表板中使用: @app.route('/dashboard/', methods=['GET', 'POST']) @login_required def dashboard():

我读了其他的问题,但还是不知道出了什么问题。 我想将一个隐藏值从一个页面:dashboard传递到另一个页面:seegoodsrec 希望有人能帮忙。 我使用此表单获取一个隐藏值:

class customerIDForm(Form):
    customerID = HiddenField()
然后在我的仪表板中使用:

@app.route('/dashboard/', methods=['GET', 'POST'])
@login_required
def dashboard():
    form = customerIDForm()
    customerID = form.customerID.data 
    return render_template("dashboard.html",form = form)
我觉得在这里很好。但是我无法理解html代码。在表格中,我希望按钮执行提交到我的页面seegoodsrec:

{% for t in TOPIC_DICT["goodsrec"] %}
<td>
<form method=post action="/seegoodsrec/">
<input type="hidden" name="customerID" value="{{j[0]}}"
    <a href="{{t[3]}}"><button type="submit" value=Save class="btn btn-primary"style=
" margin-top: 5px; margin-bottom: 5px; height:44px; margin-right: 15px">
 <span class="glyphicon glyphicon-search"></span> {{t[2]}}</button></a>
</form>
</td>
{% endfor %}
<p>test{{customerID}}</p>
页面seegoodsrec不显示来自j[0]的值customerID。非常感谢您的任何意见,谢谢!我只是想试试seegoodsrec:

{% for t in TOPIC_DICT["goodsrec"] %}
<td>
<form method=post action="/seegoodsrec/">
<input type="hidden" name="customerID" value="{{j[0]}}"
    <a href="{{t[3]}}"><button type="submit" value=Save class="btn btn-primary"style=
" margin-top: 5px; margin-bottom: 5px; height:44px; margin-right: 15px">
 <span class="glyphicon glyphicon-search"></span> {{t[2]}}</button></a>
</form>
</td>
{% endfor %}
<p>test{{customerID}}</p>
编辑

很抱歉,这么痛苦,但我就是想不出正确的方法。也许我的页面中的屏幕截图有助于:

因此,基本上,我需要做的是:当我单击查看详细信息时,我只想根据ID在我单击的行中查看客户的详细信息。查看详细信息将带我进入一个名为seegoodsrec的新页面。因此,我的想法是将一个隐藏的值传递给页面seegoodsrec,这是客户ID。然后,我可以使用该值仅显示该客户的好接收者


非常感谢你的帮助

你在这里做错了

@app.route('/dashboard/', methods=['GET', 'POST'])
@login_required
def dashboard():
    form = customerIDForm()
    customerID = form.customerID.data
    ^ ~~~~~~~~
     This doesn't do anything. Consider doing it reverse?
    return render_template("dashboard.html",form = form)

另外,GET和POST是不同的。请将它们限制为一个,或者编写单独的处理程序。

如果这对任何人都有帮助的话。以下是我如何进行选择:

<form method=post action="/seegoodsrec/">                    
<a href="{{t[3]}}"><button type="submit" name="customerID"
value="{{j[0]|int}}" class="btn btn-primary" style=" margin-top: 5px;
margin-bottom: 5px; height:44px; margin-right: 15px">
<span class="glyphicon glyphicon-search"></span> {{t[2]}}
</button>
</a>
</form>
在烧瓶中:

def seegoodsrec():
customerID = request.form.get('customerID')
mySQL3 = SelectGoodsrec(session['ID']) #displayed goodsreceiver with user ID
mySQL8 = SelectGoodsrecSEE(customerID)
c, conn = connection()

x = c.execute("SELECT * FROM goodsrec WHERE Gr_Cm_id = (%s)",
                      [str(customerID)])
if int(x) < 1:
    flash("Please, create a goods receiver for this customer")

mySQL8获取customerID并选择相应的商品接收者

等等,你听说过会话和饼干吗?是的,我听说了。。事实上,我正在使用它们。。但我不太确定我是否能在两页之间做到。。我的理解是session指的是全局用户session,但我想计算的customerID可能会在两个页面之间发生变化,这取决于我在表中单击的位置。@MarkWellings您可以描述一下您的用例吗,这样就更容易提出解决方案。FlaskApp应该为供应商处理发票。作为供应商,我必须创造我的客户,每个客户都可以有不同的货物接收方。有一个我的客户概览和一个按钮,可以查看他们各自的货物接收者。form.customerID.data=customerID给我一个错误。每个客户都有一个ID,在插入数据库时分配该ID。由于输入隐藏在html中,我试图将j[0]中的变量传递给我的页面seegoodsrec。在这里,我只想显示商品接收者的ID,ID是从我文章中的仪表板html第三个代码中获得的。如果你想以任何方式呈现它,你应该将customerID传递给模板引擎。您似乎也使用了WTForms错误,请再次阅读教程以了解正确的方法。您可以给出一个如何将hiddenvalue从一个页面传递到另一个页面的示例吗?我想那会有很大帮助。