Google News
logo
Flask - Interview Questions
How to import function into main file in flask?
You can use the import statement to import functions from other files into the main file in the Flask. You can also use the 'from' statement with the 'import' statement to import a specific function from other files into your main flask file.
 
//example of importing functions
from otherFile import function  //importing function method from the file otherFile.py
@app.route("/")
@app.route("/index")
def index():
    baz = function()     //the function imported from your file otherFile.py
if __name__ == '__main__':
    app.run(debug=True)

 

Advertisement