Project 2 - Super Hero Views
Goals
- Understand how to create views in Django
- Create templates for HTML
- Create class-based generic views
- Hook URL routes to views
- Eliminate code duplication
- Serving static media
Steps
Create the project
- Create a folder week2
- Build a project named Superhero
- django-admin startproject Superhero config .
- Build an app "hero"
- python manage.py startapp hero
- Test the blank app
Create view with an HTML template
- Write the template
- Write the view
- Write the url
- Test that the page displays
Create two hero templates
- Build the HTML
- Build the views
- Hook up the URLs
- Test
Add images
- Find images and put them in "static/images"
- Configure static server
Pass data from views to template
- Pass in the name of each hero
- Test
Test the pages
- runserver
-
browse to localhost:8000
Works
http://127.0.0.1:8000/hero/hulk http://127.0.0.1:8000/hero/black_widow
Doesn't Work
http://127.0.0.1:8000/hero/iron_man http://127.0.0.1:8000/hero http://127.0.0.1:8000