【发布时间】:2013-07-26 06:41:30
【问题描述】:
问题:
我在表单中有一个输入按钮,当它提交时应该将两个参数 search_val 和 i 重定向到 more_results() 函数(如下所列),但是当 wsgi 构建时出现类型错误.
错误是:TypeError: more_results() takes exactly 2 arguments (1 given)
html:
<form action="{{ url_for('more_results', past_val=search_val, ind=i ) }}" method=post>
<input id='next_hutch' type=submit value="Get the next Hunch!" name='action'>
</form>
烧瓶功能:
@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
)
知道如何克服构建错误吗?
我尝试过的:
Creating link to an url of Flask app in jinja2 template
通过 url_for() 使用多个参数
Build error with variables and url_for in Flask
类似的构建错误
作为旁注,该函数的目的是在有人点击“下一页”按钮时遍历列表。我正在传递变量i,所以我可以有一个参考来不断增加列表。有没有更好的烧瓶/神社 2 方法?我研究了cycling_list 功能,但它似乎无法用于渲染页面,然后使用cycling_list.next() 重新渲染它。
【问题讨论】: