Skip to content

Flask Setup (VS Code)

This tutorial assumes that you already have recent versions of Python and VS Code installed, and that you have written Python programs before in VS Code. If not, please see Getting Started with Python in VS Code.

Step 1. Install Flask

Flask is a framework for writing web applications in Python. Follow the Installation instructions to:

  1. Create and activate a virtual environment.
  2. pip install Flask in your .venv folder.

Step 2. Hello, World!

Follow the Quickstart instructions to:

  1. Save the example code in a file named hello.py.
  2. Run flask --app hello run --debug from the terminal.
  3. Open http://127.0.0.1:5000/ in a browser.

You need only read the first section ("A Minimal Application"). We will discuss the rest of the quickstart in future classes. (Feel free to read ahead, though!)

Step 3. Install Psycopg

Psycopg is a library for connecting to PostgreSQL from Python. Follow the Installation instructions to:

  1. pip install --upgrade pip
  2. pip install "psycopg[binary]"

If those two commands don't work in your virtual environment, then see the additional instructions on that page.

You can learn more about psycopg by reading Getting started with Psycopg 3.

Step 4. Example Apps

We will look at these examples during class, but make sure you can run them on your computer too.

  1. Download the cars.zip example application. Unzip the files into your folder with the virtual environment. See if you can step through cars.py and cars.html with the debugger.

  2. Download the imdb.zip example application. Unzip the files into your folder with the virtual environment. See if you can step through db.py, app.py, and gui.py with the debugger.

You can learn more about Jinja template by reading Template Designer Documentation.