'Flask API Calling a Method from Itself
My question is, can an endpoint in a Flask API call a method from another endpoint, that is a member of itself? Is there a proper way of doing this?
Solution 1:[1]
Yes, you can indeed call another endpoint by using redirect with url_for
If this is something you are trying to achieve.
from flask import Flask, redirect, url_for
app = Flask(__name__)
@app.route('/')
def hello_world():
return "Hello world"
@app.route('/home')
def hello_again():
return redirect(url_for('.hello_world'))
if __name__=="__main__":
app.run(debug=True)
The request to /home will redirect you to /.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ShivaGaire |
