Skip to main content

django-dynamic-template

Django app for content-type–scoped dynamic templates: store DTL fragments in the database, address them with a named_id slug (django-namedid), inject optional related querysets and a structured object dict into each fragment.

Requirements

  • Python ≥ 3.10
  • Django ≥ 3.2
  • django-namedid (declared in pyproject.toml; VCS pin until stable wheels are available)

Installation

From the repository root (editable install recommended for local work):

pip install -e .

Add the app and dependencies you need:

INSTALLED_APPS = [
    # ...
    "dynamic_template",
]

Optional: django-boosted (admin preview), django-richtextfield (TinyMCE-style widget) — see pyproject.toml [project.optional-dependencies] dev.

Concepts

Piece Role
DynamicTemplate label, content_type, named_id, template (richtext), plus model_fields, annotate_fields, fields shaping object in the fragment
DynamicRelationContext Related queryset (manager + filters), same three JSON fields per row; rows are tuples of dicts in the fragment
{% dyntpl %} Loads a template by named_id, merges context, evaluates relation contexts, then replaces object with a plain dict
  • model_fields: ORM column names (empty → all concrete fields on the model).
  • annotate_fields: list of annotation aliases already on the queryset / instance — this app does not call .annotate(); your manager or view must provide them.
  • fields: extra Python names resolved with getattr (@property, class attributes, methods).

Filters on relations: filter_spec (resolved from object + template context) and filter_literal (static ORM kwargs). See docs/purpose.md for full detail.

Template tag

{% load dyntpl %}

{% dyntpl "my-block-named-id" %}
{% dyntpl tpl_id obj=article %}
{% dyntpl tpl_id ctype=Product obj=product %}
  • obj=: must match the template’s content_type.
  • ctype=: disambiguates when the same named_id exists for several models.
  • Other keyword arguments are merged into the inner fragment context.

In the fragment, use {{ object.name }}, {% for row in article %}{{ row.title }}{% endfor %}, {{ rows|length }} (not .count on querysets).

Settings (optional)

# Import path to a widget class for the template field in admin
DYNAMIC_TEMPLATE_RICHTEXT_WIDGET = "djrichtextfield.widgets.RichTextWidget"

Development

pytest

pyproject.toml sets DJANGO_SETTINGS_MODULE=tests.settings and pythonpath=["src"].

Apply migrations for the bundled test project:

PYTHONPATH=src DJANGO_SETTINGS_MODULE=tests.settings python manage.py migrate

More detail: docs/ (purpose.md, structure.md, development.md).

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_dynamic_template-0.3.1.tar.gz (29.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_dynamic_template-0.3.1-py3-none-any.whl (33.0 kB view details)

Uploaded Python 3

File details

Details for the file django_dynamic_template-0.3.1.tar.gz.

File metadata

  • Download URL: django_dynamic_template-0.3.1.tar.gz
  • Upload date:
  • Size: 29.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for django_dynamic_template-0.3.1.tar.gz
Algorithm Hash digest
SHA256 0ed6577d1f91fab7e7bd677b8e9cb431818f5ae8af0cfe38145adfff3b1226a2
MD5 e23df5ce46d946b843e754ed8c5a0f0b
BLAKE2b-256 8b1296ddbec8deed949698613d4d7f4e74545be2975464494a3d53120a35c4fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_dynamic_template-0.3.1.tar.gz:

Publisher: release.yml on octolo/django-dynamic-template

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_dynamic_template-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_dynamic_template-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b7d5dd6caa1bfef6415b1a8db57a7058368277b9ae612abbcd532647e16c17bf
MD5 9ceeee7ca61ad9d4ffaba83d6fb6043c
BLAKE2b-256 52c4949aa847f3f2294f34d0f5bafdfac35bfd494082a426fbec2da51c056bcb

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_dynamic_template-0.3.1-py3-none-any.whl:

Publisher: release.yml on octolo/django-dynamic-template

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 files

0.3.0

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page