Skip to main content

Django app for content-type–scoped dynamic templates with NamedID slugs

Project description

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

Project details


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.1.1.tar.gz (20.0 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.1.1-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for django_dynamic_template-0.1.1.tar.gz
Algorithm Hash digest
SHA256 85364785bbf63c89ced12a71dcf27126761adda075977c02fdebbe2916b466ed
MD5 af5aab2cb7415cdf5b55a6e882d6856a
BLAKE2b-256 f2bc2d69ff73cc62c9ece5539f68c9918587e76405d74696986e7dcfa43d79e1

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_dynamic_template-0.1.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.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_dynamic_template-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d733b94f4436d3abdf13c1f202a35efcb06d00846762f4f62088b1bee9db23ea
MD5 9cc6bcb3849e56aa0225fef90e3863ed
BLAKE2b-256 0c65e937425a8e8c53630b459b855079eb8b47b4aac3cca925650cf435f12389

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_dynamic_template-0.1.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.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page