Fall 2026
  • Discord
  • Gradescope
  • Syllabus

On this page

  • Start
  • Build the message board
  • Check and submit

Lab: FastAPI App

Due: Wednesday, December 9 at 11:59pm (one week after it is assigned) · Worth: 8 points

A backend connects a website to its data. You’ll build a small social site in FastAPI that reads users and posts from a database and displays them in a browser. You’ll use this site again for the final project.

Start

Download the website starter, open the extracted folder, and publish it as twitter-clone. If you already have that repository, follow the guide to adding the starter.

With its Python environment active, run:

python -m pip install -r requirements.txt
python -m pytest test_setup.py
python -m uvicorn app:app --reload

Open http://127.0.0.1:8000/health. You should see a small ready message. The starter sets up the server, templates, static files, and database. The home page will not exist until you write its route. Keep credentials and the local database out of Git.

Build the message board

Write the five routes inside create_app in app.py, before return app, and complete the pages in templates/. Start by passing sample messages to a template, then replace them with rows from the database. Use the template example and the SQL reading’s join explanation.

Keep each message’s fields together in its article so its author and timestamp stay associated with the correct post. Use SQL placeholders for any user-supplied values. Put your image and stylesheet in static/, which the starter already serves.

Use with connect(request) as db: for database queries. The helper opens the database for this app, commits successful changes, and closes the connection. Keep using it in the final project so your tests can pass a separate database path to create_app(path), as in test_setup.py.

  • Create five working HTML routes: /, /login, /logout, /create_message, and /create_user. Each must use its own template extending base.html, with its own <h2>.

  • Put the shared site <h1> and links to all five routes in base.html.

  • On /, display each saved message’s body, author username, author age, and timestamp. Put them together in an <article data-message-id="..."> using the database message ID. Use <time datetime="..."> with the full timestamp and readable date/time text.

  • Read all messages with a join on messages.sender_id = users.id, select the message ID, and order newest first. Include authors of every age.

  • Serve an image from static/ and display it on /.

  • Serve a CSS file from static/ and link it in base.html so every page uses it.

Check and submit

Start the server from the repository root:

python -m uvicorn app:app --reload

Open http://127.0.0.1:8000. Follow all five menu links and check their headings and shared styles. On Home, check the image, every saved message’s fields, and newest-first order. See the server guide for connection and missing-file problems.

Commit the completed app, templates, static assets, database initialization files, dependencies, and .gitignore. Create and submit a lab-submission branch through Gradescope’s GitHub option. Then return to your default branch and merge the lab work there for the final project. Keep lab-submission unchanged after submitting. The branch guide gives the commands.