Django Foundation
The project is built on Django, a high-level Python web framework that follows the MVT pattern:- Models: Define data structure and business logic
- Views: Handle request/response logic
- Templates: Render HTML with dynamic content
- URLs: Map URL patterns to views
Project Entry Point
The project starts withmanage.py, which loads the Django settings module:
Wagtail CMS Layer
Wagtail extends Django with a powerful content management system that provides:- Page Models: Hierarchical content structure with a tree-based page system
- StreamField: Flexible content blocks for rich page layouts
- Snippets: Reusable content pieces (like People, Footer Text)
- Admin Interface: Beautiful, user-friendly editing experience
- API: Built-in REST API for headless CMS usage
Page Hierarchy
All content pages inherit fromwagtail.models.Page, creating a tree structure:
Application Architecture
The Bakery Demo is organized into Django apps, each handling a specific domain:base
Core functionality, shared blocks, HomePage, StandardPage, and common models like Person
blog
Blog functionality with BlogPage and BlogIndexPage models
breads
Bread catalog with BreadPage, ingredients, and countries of origin
recipes
Recipe pages with advanced StreamField blocks for ingredients and steps
locations
Bakery location pages with operating hours and map integration
people
Person snippet model shared across blog posts and recipes
search
Search functionality across all content types
URL Routing
The project uses a layered URL routing system defined inbakerydemo/urls.py:
The Wagtail URLs pattern (
path("", include(wagtail_urls))) must come last as it acts as a catch-all, routing requests based on the page tree structure.How Apps Work Together
1. Shared Content with Relationships
Apps are interconnected through Django’s relationship fields:2. Shared StreamField Blocks
Thebase app defines BaseStreamBlock used across multiple apps:
3. API Integration
All apps expose their content through a unified API defined inapi.py:
Settings Architecture
Settings are organized hierarchically inbakerydemo/settings/:
base.py
Contains common settings used across all environments:
- Installed apps
- Middleware configuration
- Database settings
- Static/media file configuration
- Wagtail-specific settings
dev.py
Development-specific settings:
- Debug mode enabled
- Development database configuration
- Debug toolbar settings
production.py
Production-specific settings:
- Security settings
- Performance optimizations
- Production database configuration
- Cloud storage settings
Installed Apps Configuration
TheINSTALLED_APPS in settings/base.py shows the layered architecture:
Database Architecture
The project supports multiple database backends:SQLite is used for development and PostgreSQL is recommended for production.
Search Architecture
Wagtail provides a unified search interface:Key Architectural Patterns
Model Inheritance
Model Inheritance
All page models inherit from
wagtail.models.Page, which provides:- URL routing
- Permission management
- Version control
- Page tree structure
- SEO fields
ParentalKey Relationships
ParentalKey Relationships
Used for inline relationships that should be saved atomically with the parent:
Snippets vs Pages
Snippets vs Pages
- Pages: Hierarchical content with URLs (BlogPage, RecipePage)
- Snippets: Reusable content without URLs (Person, FooterText, BreadIngredient)
StreamField Pattern
StreamField Pattern
Flexible content composition using blocks:
- Define block types in
blocks.py - Combine blocks into StreamBlock classes
- Add StreamField to models
- Render with templates
Next Steps
Project Structure
Explore the directory layout and key files
Content Models
Learn about page models and their relationships
StreamField Blocks
Understand flexible content blocks

