Home > OS >  Handling an url inside flask rule
Handling an url inside flask rule

Time:06-04

I want my web to be able to handle urls inside the rule, just like: http://127.0.0.1:5000/tiyee?url=https://tiyee.cn/iyu2 but getting an error:
Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

I've tried with this code below but seems like it doesn't work

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)

Q: Is there a way to add url inside route rule? example: example.com/tiyee?url=https://tiyee.cn/iyu2 and get the https://tiyee.cn/iyu2

CodePudding user response:

You are passing the url data in query. You will need to use request object to get the query value.

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'])
  • Related