mirror of
https://github.com/django-components/django-components.git
synced 2025-11-12 11:57:38 +00:00
|
Some checks are pending
Docs - build & deploy / docs (push) Waiting to run
Run tests / build (windows-latest, 3.10) (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.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
Co-authored-by: RohanDisa <105740583+RohanDisa@users.noreply.github.com> |
||
|---|---|---|
| .. | ||
| images | ||
| component.py | ||
| page.py | ||
| README.md | ||
| test_example_fragments.py | ||
HTML fragments
Fragments are pieces of HTML that are inserted into the page without a full page reload. Fragments are also known as partials or HTML-over-the-wire.
The usual flow is to:
- Make a server request
- Server responds with new HTML
- Insert the new HTML into the page
This example loads HTML fragments using different client-side techniques: vanilla JavaScript, AlpineJS, and HTMX.
In each of the 3 cases, when the fragment is loaded, this also runs the fragment's JS and CSS code.
Definition
--8<-- "docs/examples/fragments/component.py"
Example
To see the component in action, you can set up a view and a URL pattern as shown below.
views.py
--8<-- "docs/examples/fragments/page.py"
urls.py
from django.urls import path
from examples.pages.fragments import FragmentsPage
urlpatterns = [
path("examples/fragments", FragmentsPage.as_view(), name="fragments"),
]
