更新时间:2023-11-27 19:54:34
非常简单 - 在尖括号之间传递路径参数,但一定要将该名称传递给你的方法。
@ app.route('/ page /< page_id>)
def page(page_id):
pageid = page_id
#你可能想返回某种类型的响应...
I am using flask. I have a url such as: http://example.com/page/page_id
I want to know how to get the page_id
part from url in the route. I am hoping I could devise some method such as:
@route('/page/page_id')
def page(page_id):
pageid = page_id
It's pretty straightforward - pass the path parameter in between angle brackets, but be sure to pass that name to your method.
@app.route('/page/<page_id>')
def page(page_id):
pageid = page_id
# You might want to return some sort of response...