使用URL传递参数


1、传递普通参数

@app.route('/article/<aid>/')
def article(aid):
    return aid

2、传递指定类型的参数

名称 描述
string 接收字符串类型
int 接收整数类型
float 接收浮点类型
path 接收带斜杠的字符串
uuid 接收唯一标识符
any 接收多个路径
@app.route('/article/<path:aid>/')
def article(aid):
    return aid


# uuid:2062b250-4b97-11ec-a0d1-a0fa6f178116
@app.route('/article/<uuid:aid>/')
def article(aid):
    return aid


@app.route('/<any(article,news):url>/')
def article(url):
    return 'same page'

3、传递查询参数

@app.route('/article/')
def item():
    aid = request.args.get('aid')
    return aid

results matching ""

    No results matching ""