python-3.x - 如何在烧瓶中实现一个嵌套路由,每个路由都做不同的事情
问题描述
@app.route('/sera/<mount_type>')
@app.route('/sera', methods=['POST'])
def return_pages():
if request.method == 'POST':
usin = request.form.get('serval')
global mount_type
mount_type = usin
#this section runs independend of the search box
if mount_type == 'acongagua':
return render_template('result.html',aa=acongagua.names, ac=acongagua.location, ad=acongagua.metre_height, ae=acongagua.feet_height)
elif mount_type == 'adams':
return render_template('result.html',aa=adams.names, ac=adams.location, ad=adams.metre_height, ae=adams.feet_height)
else:
return 'YOU HAVE ENTERED AN INCORRECT VALUE'
if __name__ == '__main__':
app.run(debug=True, use_reloader=True)
那是我正在尝试运行的python烧瓶代码第一个if语句应该在填写表格时运行,并且应该将其值传递给seconf if语句
解决方案
您可以使用redirect
重定向请求,并将值作为 URL 参数传递:
from flask import redirect
@app.route('/sera/<mount_type>')
@app.route('/sera', methods=['POST'])
def return_pages():
if request.method == 'POST':
usin = request.form.get('serval')
return redirect(url_for('return_pages', mount_type=usin)) # <--
...
推荐阅读
- python - Python - 检查 Numpy 数组中的零浮点值
- oauth-2.0 - 使用身份服务器 3.0 和 oAuth 2.0 时如何跨多个应用程序(Web/移动)共享 JWT 令牌
- angular - 在折叠时显示不同的导航栏项目(ngx-bootstrap)
- web - 你如何让一个网站被别人看到
- c# - C# 字典中的 KeyNotFoundException 在根据什么更改属性值后,计算 GetHashCode。为什么?
- rest - 为什么简单 API 控制器中不允许使用 DELETE 方法
- javascript - 在后端复制 Wordpress 标题
- php - 试图从 mysql 获取数据但导致找不到
- ios - 如何禁用多个手势识别器之一?
- python - 计算插值后 3D 规则网格数据的导数