The Wayback Machine - https://web.archive.org/web/20240204104349/https://www.geeksforgeeks.org/how-to-run-a-flask-application/
Open In App
Related Articles

How to Run a Flask Application

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
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


Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century.

Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.


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