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.3.0.tar.gz (28.9 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.0-py3-none-any.whl (32.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_dynamic_template-0.3.0.tar.gz
  • Upload date:
  • Size: 28.9 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.3.0.tar.gz
Algorithm Hash digest
SHA256 6cdd9652e021b36ce914e624040ec701a5f219b7588080075baeabc69bfc8708
MD5 c4fc814d20c7db924bfda5af51d37685
BLAKE2b-256 3718bce2dbf80fd6dafdd017e7d4b966d235385d0823066cd14e8c4644899679

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for django_dynamic_template-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed39013df6c81fdf7b009f31e3dd839f78b5becc7e248940335431e2720bc4c7
MD5 828486313668947b75f0a491984ae22b
BLAKE2b-256 54b08b493e4ace685baf0c8faae661e9f2d91f58a1df4b6961f13d5ed91ee9d1

See more details on using hashes here.

Provenance

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