处理 url inside flask 规则

Handling an url inside flask rule

我希望我的网站能够处理规则内的 URLs, 就像: http://127.0.0.1:5000/tiyee?url=https://tiyee.cn/iyu2 但出现错误:

Not Found The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

我试过下面这段代码,但似乎不起作用

from flask import Flask, redirect
from tiyee import bypasser
app = Flask(__name__)

@app.route('/tiyee?url=<url>')
def _tiyee_redirect(url):
    bypassed_json = bypasser(url)
    return redirect(bypassed_json['bypassed_link'])

if __name__ == '__main__':
    app.run(debug=True, port=5000)

问:有没有办法在路由规则中添加URL? 例子: example.com/tiyee?url=https://tiyee.cn/iyu2 并得到 https://tiyee.cn/iyu2

您正在查询中传递 url 数据。您将需要使用请求对象来获取查询值。

from flask import request
...

@app.route('/tiyee')
def _tiyee_redirect():
    _url = request.args.get('url')
    if _url is not None:
        bypassed_json = bypasser(_url)
        return redirect(bypassed_json['bypassed_link'])