Project 9 - View Inheritance
Goals
- Build an application to support the CRUD operations
- Data Views
- Superhero
- Users
- Article
- Use View Tricks
- View Inheritance
- extends "theme.html"
- Partial Templates
- include "_navbar.html"
- include "_user.html"
- include "_header.html"
- include "_footer.html"
- View Inheritance
- User Management
- Users can Register
- Users login/logout
- Edit operations require login
Steps
Test-driven Development
- Define TestSuperhero(TestCase)
- Define TestArticle(TestCase)
- Build in fixed order
- Data
- Templates
- Views
- Urls
Shrinking World Plan
- To Do List - plan your top priorities
- Done - tell what you did
Build out the Superhero Django Project
- Data types
- Superhero (create and display superhero info)
- Article (create news articles for each superhero)
- User (require login for edit)
Create Superhero Theme
- Create a base page template
- Style all pages without duplicating any code
- Create a HTML template "superhero_theme.html"
- Add a bootstrap CSS and custom CSS to this template
- Add a "{% block content %}" section to the template
- Make index.html and hero.html use "{% extends 'superhero_theme.html' %}"
- Debug the view inheritance
- Give you pages some cool style
Create Superhero Pages
- Build one set of templates
- Build view that take arguments and displays the contents
- Build a URL route that call your view
Create Images
- Create images that match your five selected heroes
- Add an image to your view to display the superhero image
- Debug your application code until photos display
- Commit to your Github repo
- Deploy at Python Anywhere
Superhero data records
- Superhero Record
- name
- identity
- description
- strength
- weakness
- image
- Add five Superhero data records
Article data records
- Article Record
- hero
- order
- title
- markdown
- html
- Add five views for Article data records
Use View Tricks
- View Inheritance
- Inherit from "superhero_theme.html"
- Blocks
- content
- header
- footer
- main
- navbar
- user
- Partial Templates
- _navbar.html
- _user.html
- _header.html
- _footer.html
Test the pages
- Browse to http://YOUR_USER.pythonanywhere.com for Your Site
- Make sure this address is set in Sensei
Requirements
- Your page must be available at http://YOUR_USER.pythonanywhere.com
- Superhero database table and views
- Article database table and views
- Markdown formatter
- TestSuperheroData, TestSuperheroViews, TestArticleData, TestArticleViews
- Editing requires login
- Partial templates and includes
- Register
- View Inheritance - "theme.html" base template for all pages
- Nice page style and layout