How to Run a Flask Application
The backend server Flask was created fully in Python. It is a framework made up of Python modules and packages. With its characteristics, it is a lightweight Flask application that speeds up the development of backend apps. We will learn how to execute a Flask application in this tutorial.
Run Flask application Syntax
We can run the Flask application using the below command.
flask –app <hello> run
flask run
python <app_name>.py
File Structure
Here, we are using the following folder and file.
Run a Flask Application
In this example, we have an application called helloworld.py below is the basic code for Flask.Â
Python3
from flask import Flask
app = Flask(__name__)
@app .route( "/" )
def hello_world():
return "<p>Hello, World!</p>"
if __name__ = = '__main__' :
app.run()
|
Output:
Using flask –app <app_name> run
Using flask run
Using the python app_name.py
Run the app in the debugger
We will use the below command to run the flask application with debug mode as on. When debug mode is turned on, It allows developers to locate any possible error and as well the location of the error, by logging a traceback of the error.
if __name__ == ‘__main__’: Â
 app.run(debug = True)
Last Updated :
20 Dec, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...