Open In App

How to Run a Flask Application

Improve
Improve
Like Article
Like
Save
Share
Report

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.

Screenshot-from-2023-04-13-18-07-25

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

Screenshot-from-2023-04-13-18-04-17

Using flask run

Screenshot-from-2023-04-13-17-59-57

Using the python app_name.py

Capture14

3-300x64

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)

Capture15



Last Updated : 20 Dec, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads