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
| Word | What it means | Example |
|---|---|---|
| Prototype | A working early version of an app. | |
| Framework | Ready-made code you build an app on. | Flask |
| Virtual environment | A folder that holds one project's own libraries. | .venv |
| Version control | A tool that saves every version of your code. | Git |
| Repository | The project folder that version control looks after. | |
| Blueprint | A 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 questionsSprint 0, step 1: the goal
| Part | For this step |
|---|---|
| How we work | In sprints (short blocks of work, each with one goal). |
| Goal of Sprint 0 | A project that runs, a page layout, and a database (where the app keeps its data) with sample data. |
| This step | A Flask app with one page, a virtual environment, Git and a change log. |
| User stories | None 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
| Sprint | Steps | Goal |
|---|---|---|
| Sprint 0 | 1 to 3 | Project, layout and database ready |
| Sprint 1 | 4 to 7 | Sign in and support requests |
| Sprint 2 | 8 to 9 | On-site jobs and engineers' schedules |
| Sprint 3 | 10 to 11 | Knowledge base and the customer view |
| Sprint 4 | 12 to 14 | Reports, accessibility (use by everyone) and security |
| Review | 15 to 16 | Test 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 questionsFour 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
# 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()
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 questionsA 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
| Line | Why Git skips it |
|---|---|
| .venv/ | Each computer makes its own virtual environment |
| __pycache__/ | Python makes these files again by itself |
| *.db | The 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
| Date | Version and files | What changed | Why |
|---|---|---|---|
| 2 March | step-01: __init__.py, main.py, the library list, .gitignore | A Flask app with one page, pinned libraries and a .gitignore | To 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