Overview
Friday, January 23rd
Classwork - Template Inheritance
I've updated your grades for our recent assignments:
- The reading quiz about templates
- The template-based static site generator for book reviews
- Creating simple Django templates/routes
- For those who emailed me about changes to your chat assignment, I think I've responded to everyone
As always, I make mistakes. If you have any questions or concerns about grades, email me =)
Template Inheritance
Now that we have a few templates, let's make them pretty. We'll use template inheritance for this - we'll write one pretty page and then each of our templates will just inherit the prettiness
As before, the code is a little involved and requires a good understanding of Django's organization. We'll go through this code live and slowly, but I've also posted all of the changes ahead of time here: setup template inheritance and a nice homepage . Don't just copy/paste these changes - I want you to really understand them!
Homework
Most importantly - do your best snow dance before bed tonight ☃
Other than that, pretty up your Django website:
- Add some content (maybe a header) to your base HTML file
- Personalize the base CSS
- Apply it to all of the templates that you made last time
- Make sure all of your templates are linked from your new homepage
Starting next week, we'll be branching into more complex views/templates - we'll be spinning up new templates quickly, so you need to be comfortable with this process!
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:
- Last class, we followed these steps:
- setup and activated a virtual environment
- installed django
- ran
python3 -m django startproject hello_django - cd'd into the
newly-created
hello_djangodirectory - ran
python3 -m django startapp core
http://localhost:8000/and see the rocket ship. - 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
-
After those changes, you should be able to
python3 manage.py runserverand then navigate tohttp://localhost:8000/core/to see the word 'test', and then tohttp://localhost:8000/core/icecream/chocolateto 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.
