Build a Web Site with Flask
Install Flask in a virtual environment and create a simple "Hello World" web app. You’ll learn to modify route definitions, use debug mode, and render HTML pages using Flask routes. You will also work with boilerplate HTML and CSS to customize your site, dynamically generating URLs with
url_for
, creating and inheriting Jinja templates, and defining multiple routes that link to the same function.

Build a Web Site with Flask
Install Flask
You must first have Python install: https://www.python.org/downloads/
Step 1: Open Your Terminal
- On Windows, use Command Prompt or PowerShell.
- On macOS/Linux, open the Terminal.
Step 2: Create a Workspace Directory
-
mkdir workspace
-
cd workspace
This will be the folder where you manage your Flask projects.
Step 3: (Optional) Install pip if not already installed
If pip
is not installed, you can install it using:
-
sudo pip install --upgrade pip
On Windows, you might not need sudo
.
Step 4: Install
virtualenv
-
pip install virtualenv
This allows you to create isolated environments for your Python apps.
Step 5: Create a Flask Project Folder
-
mkdir flask
-
cd flask
Step 6: Create a Virtual Environment
- python -m virtualenv flaskenv
Step 7: Activate the Virtual Environment
- On macOS/Linux:
-
flaskenv/bin/activate
- On Windows (Command Prompt):
-
flaskenv\Scripts\activate
- On Windows (PowerShell):
.\flaskenv\Scripts\Activate.ps1
After activation, your prompt will change to show (flaskenv)
Step 8: Install Flask
pip install Flask
Step 9: Test the Flask Installation
Start Python:
-
python
Then run:
-
import flask
If no error appears, Flask was installed successfully
Exit Python:
-
exit()
Step 10: Deactivate the Virtual Environment (when done)
-
deactivate


