This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Preps

This class is flipped, it’s vital that you prepare for the in-class activities by completing these preparations.

1 - Prep 01: Setup Dev Environment and Creating a skeleton website

  1. Python via uv
  2. Django 6.1.
  3. MDN Django Tutorial through Part 2
  4. Put it on github

Prereq

  1. Create a directory for 347 work on your local machine. See our docs on:
    1. Working Locally vs. Remotely
      1. 🚨 Complete the auth via keypairs steps
    2. Files

Instructions

  1. Do the following (“do” as in read, take notes, and try to make work) from our fork of the MDN Django Tutorial:
    1. Django introduction
    2. Setting up a Django development environment
    3. Django Tutorial: The Local Library website
    4. Django Tutorial Part 2: Creating a skeleton website

Submitting

  1. After you complete the steps linked above, you will have pushed some commits to a github repository.
  2. Github provides a link for each commit.
  3. Submit a commit.url file containing the url to the latest commit of your public github repo that was relevant to the steps above to gradescope.
  4. Here’s an example of what such a URL might look like https://github.com/347s26/locallibrary-hcientist/commit/caca9ecbcc79f5aa3ec29300c47c123b9a7a0ca5. See the screenshot below to see where to click to reach the right kind of URL. screenshot showing most recent commit link

2 - Prep 02: Django Models and admin from MDN Tutorial Parts 3-4

MDN Django Tutorial Parts 3-4

Continuing to work in the repo you created for Prep 01.

Part 3

  1. Do Part 3 (Models)
  2. Question: what is a migration? did we need any yet? what alternative could there have been? how do they work?! e.g.
    1. how does django know what to put in a migration?
    2. how does django know which migrations have been applied?
  3. Read “Falsehoods Programmers Believe About Names – With Examples”
    1. Based on the points in the article, what (if any) changes might you propose to the models in this Prep?
    2. Have you ever been unsure how to enter information about yourself into a computer system?
      1. What information were you trying to enter?
      2. Do you recall what system?
      3. What was the cause of your uncertainty?
      4. (reflect on this personally, and if you have reflections that you wish to share that don’t doxx you, feel free to bring them to in-class discussion)
  4. Consider installing some database tools:
    1. GOAT: DBeaver Community (supports pretty much every kind of db ever)
    2. db-specific:
      1. DB Browser for SQLite
      2. PGAdmin for PostgresQL (we don’t need the PostgresQL stuff yet)

Best Practices: env files (for repeatability, secrets, and great good)

env files help track configuration information. Often these values may differ on different machines of your own or at least between you and a team member, and likely also between your machine for (local) development and your server(s) in the cloud that hosts your app.

Because it might be convenient to discard and recreate your database on occasion, and also to have consistent expectations for troubleshooting across all the students’ computers, make these files so that we don’t have to waste time waiting for you to re-find your django admin user’s password.

  1. Ensure that your .gitignore
    1. exists at all 😆
      1. if it doesn’t, maybe start from a good Python .gitignore template such as that provided by github
    2. has .env in it
  2. Create a file named .env.example in the root of your project (so it’s a sibling of catalog/, locllibrary_config/, and manage.py) with this code:
    DJANGO_SUPERUSER_USERNAME="me"
    DJANGO_SUPERUSER_PASSWORD="me"
    DJANGO_SUPERUSER_EMAIL="me@me.me"
    
  3. save a copy of that file as .env

We could add other things here, but this is all we need for now.

Instruct django project to use env file

  1. add django-environ as a dependency: uv add django-environ
  2. edit settings.py to
    1. import environ at the top
    2. immediately after the definition of BASE_DIR, add the following
      env = environ.Env()
      # FYI: OS environment variables take precedence over variables from .env
      env.read_env(str(BASE_DIR / ".env"))
      

create superuser with values from env

With this env file created and expected in your settings, you can add an argument to the django-admin createsuperuser command to have it default to these values:

uv run python manage.py createsuperuser --no-input

Part 4

  1. Do Part 4 (admin site).

Submitting

  1. Push your updated code back to your github repo
  2. submit the most recent commit URL to the gradescope assignment in a file called commit.url.

3 - Prep 03: Django Admin Site and Home Page from MDN Tutorial Part 5

MDN Django Tutorial Part 5
  1. Continuing to work in the repo you created for Prep 01, and extended in Prep 02, complete MDN Django Tutorial Part 5.
    • Note: Near the end of Part 5, the tutorial fails to mention that if you have had your development server (the one you get with the runserver command) running the whole time you were working on this Part, you’ll have to kill it and start it again before you can expect django to find your new template.
  2. Push your updated code back to the github repo
  3. submit the most recent commit URL to the gradescope assignment.