django-components/sampleproject/examples
Juro Oravec 49afdb49d6
Some checks are pending
Docs - build & deploy / docs (push) Waiting to run
Run tests / build (ubuntu-latest, 3.10) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.11) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.12) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.13) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.8) (push) Waiting to run
Run tests / build (ubuntu-latest, 3.9) (push) Waiting to run
Run tests / build (windows-latest, 3.10) (push) Waiting to run
Run tests / build (windows-latest, 3.11) (push) Waiting to run
Run tests / build (windows-latest, 3.12) (push) Waiting to run
Run tests / build (windows-latest, 3.13) (push) Waiting to run
Run tests / build (windows-latest, 3.8) (push) Waiting to run
Run tests / build (windows-latest, 3.9) (push) Waiting to run
Run tests / test_docs (3.13) (push) Waiting to run
Run tests / test_sampleproject (3.13) (push) Waiting to run
docs: Add "scenarios" code examples (#1445)
2025-10-08 00:17:31 +02:00
..
__init__.py docs: add Form and Tabs examples (#1411) 2025-09-29 15:58:47 +02:00
apps.py docs: self-contained examples (#1436) 2025-10-05 09:09:08 +02:00
README.md docs: Add "scenarios" code examples (#1445) 2025-10-08 00:17:31 +02:00
urls.py docs: Add "scenarios" code examples (#1445) 2025-10-08 00:17:31 +02:00
utils.py docs: self-contained examples (#1436) 2025-10-05 09:09:08 +02:00
views.py docs: Add "scenarios" code examples (#1445) 2025-10-08 00:17:31 +02:00

Examples

This Django app dynamically discovers and registers example components from the documentation (docs/examples/).

How it works

  1. Discovery: At startup, the app scans docs/examples/*/ directories for:

    • component.py - Component definitions with inline templates
    • page.py - Page views for live demos
  2. Registration: Found modules are imported as:

    • examples.dynamic.<example_name>.component
    • examples.dynamic.<example_name>.page
  3. Components: Are automatically registered with django-components registry via @register() decorators

  4. URLs: Page views are automatically registered as URL patterns at examples/<example_name>

Structure

Each example in docs/examples/ follows this structure:

docs/examples/form/
├── README.md           # Documentation
├── component.py        # Component with inline templates
├── page.py            # Page view for live demo
├── test.py            # Tests
└── images/            # Screenshots/assets

Live examples

All examples are available as live demos:

Adding new examples

  1. Create a new directory in docs/examples/<example_name>/
  2. Add component.py, page.py, and other files as seen above.
  3. Start the server and open http://localhost:8000/examples/<example_name> to see the example.