通过把 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快速上手》
更多推荐
flask html 下一页 第几页,flask在不同的html页面中怎样传递参数?
发布评论