Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Handling an url inside flask rule

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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'])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading