- Create and run your first Flask app
- Set the values of
FLASK_APP
andFLASK_DEBUG
environment variables
A minimal Flask application can easily be created in 3 steps and as little as 5 lines of code.
- Create a file named
app.py
inside yourportfolio
project folder:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
- In your terminal or console, navigate to the location of your project folder and set the
FLASK_APP
environment variable:
Mac:
export FLASK_APP=app.py
Windows:
set FLASK_APP=app.py
- Finally, run your application:
flask run
Congratulations! You can now access your app through the url route generated in your terminal or console using your favorite browser.
To quit, press CTRL+C
.
To deactivate your virtual environment, enter deactivate
.
To run your app in debug mode, set the FLASK_DEBUG
environment variable to 1 before running the application:
Mac:
export FLASK_DEBUG=1
Windows:
set FLASK_DEBUG=1