为了账号安全,请及时绑定邮箱和手机立即绑定

flask在不同的html页面中怎样传递参数?

flask在不同的html页面中怎样传递参数?

凤凰求蛊 2018-09-12 10:10:37
例如我想实现在A页面点击一个按钮,把A页面中的一个id值传到B页面(同时跳转到B页面)?用jquery ajax吗?求具体点的方案
查看完整描述

1 回答

?
Helenr

TA贡献1780条经验 获得超3个赞

通过把 URL 的一部分标记为 <variable_name> 就可以在 URL 中添加变量。
标记的 部分会作为关键字参数传递给函数。通过使用 <converter:variable_name> ,可以选择性的加上一个转换器,为变量指定规则。

@app.route('/user/<username>')def show_user_profile(username):    # show the user profile for that user
    return 'User %s' % username

@app.route('/post/<int:post_id>')def show_post(post_id):    # show the post with the given id, the id is an integer
    return 'Post %d' % post_id

转换器有: 
int 接受整数
float 接受浮点数
path 和缺省情况相同,但也接受斜杠

URL 构建是通过 url_for() 函数来操作的。


查看完整回答
反对 回复 2018-10-13
  • 1 回答
  • 0 关注
  • 2471 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信