- Create and run your first Flask app
- Set the values of
FLASK_APPandFLASK_DEBUGenvironment 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.pyinside yourportfolioproject 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_APPenvironment variable:
Mac:
export FLASK_APP=app.py
Windows:
set FLASK_APP=app.py- Finally, run your application:
flask runCongratulations! 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