set environment variable flask app

  1. Open a terminal or command prompt.

  2. Navigate to the directory where your Flask application is located.

  3. Set the environment variable for the Flask application by using the following command:

bash export FLASK_APP=your_app_name.py

Replace "your_app_name.py" with the actual name of your Flask application file.

  1. Optionally, you can set the environment to development mode to enable debugging and automatic reloading:

bash export FLASK_ENV=development

This step is recommended during development but should be avoided in production.

  1. Confirm that the environment variable is set correctly by checking the output of the following command:

bash echo $FLASK_APP

The terminal should display the name of your Flask application file.

  1. You can now run your Flask application using the following command:

bash flask run

This command starts the Flask development server, and you can access your application in a web browser at the specified address (usually http://127.0.0.1:5000/).