Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Task 2 A, B: Setting up the Flask project

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

60 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

Clear the site before you build

A builder does not start with the roof. First the site is cleared, the tools are checked and the plan goes up on the wall.

Task 2 starts the same way. You have a design from Task 1. Now you build it, in about 20 hours.

One good hour of set-up means every later hour goes on real features.

Key words

WordWhat it meansExample
PrototypeA working early version of an app.
FrameworkReady-made code you build an app on.Flask
Virtual environmentA folder that holds one project's own libraries..venv
Version controlA tool that saves every version of your code.Git
RepositoryThe project folder that version control looks after.
BlueprintA group of related pages in their own file.

The cells students fill in are left blank in this preview.

By the end of this lesson

Note

I can set up a Flask project that runs, with Git and a virtual environment.

Starter: what you already know

Have a go

Starter: what you already know

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Sprint 0, step 1: the goal

PartFor this step
How we workIn sprints (short blocks of work, each with one goal).
Goal of Sprint 0A project that runs, a page layout, and a database (where the app keeps its data) with sample data.
This stepA Flask app with one page, a virtual environment, Git and a change log.
User storiesNone yet. This step makes the place where every story will live.

The cells students fill in are left blank in this preview.

What Task 2 asks you to make

You build a working prototype of the Netheret app you designed. It needs a front end and a back end. It must use at least two languages. Here they are Python on the server and JavaScript in the browser.

Another developer should be able to read and change your code. Users should find it easy and safe.

You also keep two records: a test log, and a change and source log. At the end you record a short screencast.

The plan: five sprints and a review

SprintStepsGoal
Sprint 01 to 3Project, layout and database ready
Sprint 14 to 7Sign in and support requests
Sprint 28 to 9On-site jobs and engineers' schedules
Sprint 310 to 11Knowledge base and the customer view
Sprint 412 to 14Reports, accessibility (use by everyone) and security
Review15 to 16Test log, change and source log, screencast

The cells students fill in are left blank in this preview.

Check: what Task 2 asks for

Have a go

Check: what Task 2 asks for

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Four tools set up the project

Flask is a small Python framework for web apps. You install it with pip, Python's installer.

A virtual environment keeps this project's libraries apart from every other project. A file called requirements.txt lists them, with exact version numbers. Then everyone installs the same ones.

Git saves each version of your code. Commit after each working change, so you can always go back.

The commands that start step 1

Code: bash
# Type these in a terminal on your own computer.
mkdir netheret-helpdesk
cd netheret-helpdesk
git init

# Make the virtual environment, then switch it on.
python -m venv .venv
source .venv/bin/activate        # on Windows: .venv\Scripts\activate

# requirements.txt holds two lines:
#   Flask==3.1.3
#   Flask-SQLAlchemy==3.1.1
pip install -r requirements.txt
flask --app helpdesk run --debug

Make a free account to save your work and track your progress.

Match each tool to its job

Have a go

Loading…

Your answers are marked here and are not kept. A college account keeps every student’s marks.

One function builds the whole app

The app lives in a folder called helpdesk. Its file __init__.py holds one function (a named block of code): create_app(). Flask looks for that name when you run the app.

Pages are grouped into blueprints. A blueprint is a group of pages in its own file. Later you add one file per feature: tickets, jobs, the knowledge base. Small files are easier for another developer to follow.

Step 1: create_app()

Code: python
from flask import Flask

app = Flask(__name__)
app.config['DEBUG'] = True


@app.route('/')
def hello():
    message = "Hello, Flask!"
    return message


if __name__ == '__main__':
    app.run()

Make a free account to save your work and track your progress.

Why pass __name__ to Flask()?

Some of its uses:

Locating resources

Flask looks at the value of __name__ to figure out where the app is located in the file system. This helps it:

  • Find static files (like CSS or JavaScript)
  • Find templates (like HTML files in the templates/ folder)

Debug information

To debug means to find and fix mistakes in code. Flask uses this value when it generates error messages or logs, to provide context about where the app code is located.

Check: the app's first files

Have a go

Check: the app's first files

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

A common mistake

Warning

Many students put everything into Git, including .venv and the database file. Both are made on each computer, so they should stay out. A .gitignore file lists what Git must skip. Write it before your first commit, because removing files later is harder.

The .gitignore of step 1

LineWhy Git skips it
.venv/Each computer makes its own virtual environment
__pycache__/Python makes these files again by itself
*.dbThe database is made by the app, not written by you
instance/The folder where Flask keeps the database

The cells students fill in are left blank in this preview.

Build it yourself: step 1

Build step 1 on your own computer. 1. Make a project folder and run git init. 2. Make a virtual environment and switch it on. 3. Write requirements.txt with Flask and Flask-SQLAlchemy, pinned, and install it. 4. Make the helpdesk folder with __init__.py holding create_app() and main.py holding a blueprint with one page. 5. Write .gitignore. 6. Run flask --app helpdesk run --debug and open the page. 7. Commit, then write your first change log row. Paste a screenshot of the running page and your git log.

A teacher marks this in a college. Nothing you write here is kept: it goes when you leave the page.

Make a free account to save your work, or press Start lab to work through the whole lesson.

Compare with the step 1 code

Tip

When yours runs, compare it with the step 1 code on GitHub. It holds the app up to this step and nothing more. Read it after you try, not before.

Start the change log now

DateVersion and filesWhat changedWhy
2 Marchstep-01: __init__.py, main.py, the library list, .gitignoreA Flask app with one page, pinned libraries and a .gitignoreTo prove the tools work before any features

The cells students fill in are left blank in this preview.

Next: a layout every page shares

Write one change log row at the end of every step. Keep it short: the date, the files and version, what changed and why. It is a list of milestones (big steps), not a diary.

In step 2 you move the HTML into templates. One base template gives every page the same header, menu and footer.

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.