Recently I developed a web application using flask, which has a search page and a results page. The search page has multiple forms. Currently, these forms have been successfully processed in the routing function of the search page, and the results are stored in a list type. In the variable, I want to pass this variable to another page, that is, the results page, and display the results. Is there any way to pass parameters between routes?
@app.route('/search', methods=['get', 'post']) #这是搜索页面
def fsearch():
....
if request.method == 'POST':
results = multiselect(request) #这是处理表单的函数,reslults为list类型变量
...
return render_template("new.html")
@app.route('/result', methods=['get', 'post']) #这是结果页面
def fresult():
...
return render_template("result.html")
Use a global variable
Requests directly correspond to results.
Why do you need to make another request to get the result after one request is completed?
Use the redirect function
return redirect(url_for('fresult')), and you can add parameters to the function.
Why do you have to use post? You can refer to my implementation
demo