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

查看:622
本文介绍了javascript - flask在不同的html页面中怎样传递参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

例如我想实现在A页面点击一个按钮,把A页面中的一个id值传到B页面(同时跳转到B页面)?用jquery ajax吗?求具体点的方案

解决方案

通过把 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() 函数来操作的。具体的可以看下:《Flask快速上手》

这篇关于javascript - flask在不同的html页面中怎样传递参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆