Python 具有多个参数的Flask url_for() 问题是:
我有一个表单中的输入按钮,当它被提交时,应该将两个参数,Python 具有多个参数的Flask url_for() 问题是:,python,html,flask,Python,Html,Flask,我有一个表单中的输入按钮,当它被提交时,应该将两个参数,search\u val和I重定向到more\u results()函数(如下所列),但是当wsgi构建时,我得到一个类型错误 错误是:TypeError:more\u results()正好接受2个参数(给定1个) html: 烧瓶功能: @app.route('/results/more_<past_val>_hunches', methods=['POST']) def more_results(past_val, i
search\u val
和I
重定向到more\u results()
函数(如下所列),但是当wsgi构建时,我得到一个类型错误
错误是:TypeError:more\u results()正好接受2个参数(给定1个)
html:
烧瓶功能:
@app.route('/results/more_<past_val>_hunches', methods=['POST'])
def more_results(past_val, ind):
if request.form["action"] == "Get the next Hunch!":
ind += 1
queried_resturants = hf.find_lunch(past_val) #method to generate a list
queried_resturants = queried_resturants[ind]
return render_template(
'show_entries.html',
queried_resturants=queried_resturants,
search_val=past_val,
i=ind
)
@app.route('/results/more\uu hunches',methods=['POST'])
定义更多结果(过去值,索引):
if request.form[“action”]=“获取下一个预感!”:
ind+=1
查询的_resturants=hf.find _午餐(过去的_val)#方法生成列表
查询的餐厅=查询的餐厅[ind]
返回渲染模板(
“show_entries.html”,
查询的餐厅=查询的餐厅,
搜索值=过去值,
i=ind
)
你知道如何克服构建错误吗
我所尝试的:
用于使用url_for()的多个参数
类似的构建错误
作为旁注,该函数的目的是在有人点击“下一页”按钮时遍历列表。我正在传递变量
I
,这样我就可以有一个引用在列表中不断递增。是否有一种烧瓶/jinja 2方法更有效?我已经研究了循环列表功能,但它似乎无法用于呈现页面,然后使用循环列表重新呈现页面。下一步()
您的路线没有指定如何填充多个过去的值。如果不提供双参数模式,Flask无法神奇地创建将传递两个参数的URL。也可以通过为某些参数指定默认值来创建支持可变数量参数的路由:
@app.route('/foo/<int:a>')
@app.route('/foo/<int:a>/<int:b>')
@app.route('/foo/<int:a>/<int:b>/<int:c>')
def test(a, b=None, c=None):
pass
@app.route(“/foo/”)
@app.route(“/foo/”)
@app.route(“/foo//”)
def测试(a,b=无,c=无):
通过
在处理烧瓶中的多步骤表单时,上述答案是否可以被视为正确的方法?这样,每一步都是一个参数。@plaes这对我不起作用。如果我不传递参数b和c,它会给出404
@app.route('/foo/<int:a>')
@app.route('/foo/<int:a>/<int:b>')
@app.route('/foo/<int:a>/<int:b>/<int:c>')
def test(a, b=None, c=None):
pass