run flask in debug mode

To run Flask in debug mode, follow these steps:

  1. Import the Flask module: Begin by importing the Flask module into your Python script. This module provides the necessary functionality to create a Flask application.

  2. Create an instance of the Flask class: Create an instance of the Flask class and assign it to a variable. This instance will be your application object.

  3. Set the debug mode: To enable debug mode, set the debug attribute of the application object to True. This will allow the application to automatically reload whenever a change is made to the source code, providing real-time updates.

  4. Run the application: Use the run() method of the application object to start the Flask development server. This method takes several optional arguments, such as host and port, to customize the server's behavior. By default, the server will listen on localhost ( and port 5000.

Here is an example of running Flask in debug mode:

from flask import Flask

app = Flask(__name__)
app.debug = True

def hello():
    return 'Hello, World!'

if __name__ == '__main__':

In this example, the Flask module is imported, an instance of the Flask class is created, the debug mode is enabled by setting the debug attribute to True, and the application is run using the run() method.

Running Flask in debug mode allows you to easily debug your application by providing detailed error messages and a built-in interactive debugger. However, it is important to note that debug mode should not be used in a production environment, as it can expose sensitive information and pose security risks.