Run a Flask Application
In this example, we have an application called helloworld.py below is the basic code for Flask.
Python3
# import flast module from flask import Flask # instance of flask application app = Flask(__name__) # home route that returns below text when root url is accessed @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)
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.
Contact Us