Grace Hopper Center

CSC 221 Weekly Assignments: Week 19

CSC 221


Overview

Wednesday, January 21st

Classwork

We'll pick up where we left off last week - we're trying to create an entire view (with accompanying template) from scratch. We'll walk through this together and then you'll repeat the process on your own for homework.

For those who had trouble following along in class today, or just need a review, here's some commits you can review:

  1. Last class, we followed these steps:
    1. setup and activated a virtual environment
    2. installed django
    3. ran python3 -m django startproject hello_django
    4. cd'd into the newly-created hello_django directory
    5. ran python3 -m django startapp core
    Those commands auto-generate a whole bunch of files, which you can see in this commit. (you shouldn't have to write any of these files yourself, just run the django commands). At this point you should be able to navigate to http://localhost:8000/ and see the rocket ship.
  2. Today in class, we worked forward from there. We had to modify a few files and create a few more. Here is my commit that includes all of those changes
  3. After those changes, you should be able to python3 manage.py runserver and then navigate to http://localhost:8000/core/ to see the word 'test', and then to http://localhost:8000/core/icecream/chocolate to see the icecream template with the variable "chocolate" filled in

I know this was a lot. Please try your best for homework. If you get stuck, commit your work and email me so I can take a look!

I also want you to be comfortable with the directory tree we discussed in class. Django can certainly be confusing at first - with all the multiple files that have the same names. Here's the tree we drew on the board today. There is a lot omitted from this diagram, these are the only files that I want you to know for now.

hello_django
├── core
│   ├── templates
│   │   └── core
│   │       ├── icecream.html
│   │       └── index.html
│   └── urls.py
├── db.sqlite3
├── hello_django
│   ├── settings.py
│   └── urls.py
└── manage.py

Homework

You should make a total of **three** new templates (not counting our icecream example from Monday). Each template should:

  • Be linked from your index.html page
  • Take an input parameter, using the URL template example from Dr. Chuck's video, and display it in the template

This assignment is due before the start of class on Wednesday. We'll grade each-other's pages at the start of class on Wednesday.