首頁  >  問答  >  主體

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

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

高洛峰高洛峰2914 天前1348

全部回覆(1)我來回復

  • 三叔

    三叔2016-10-27 14:04:23

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

    @app.route('/user/')
    def show_user_profile(username):
        # show the user profile for that user
        return 'User %s' % username
    
    @app.route('/post/')
    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快速上手》


    回覆
    0
  • 取消回覆