Skip to main content

Template loader for templates stored in the database (IPLweb maintenance fork)

Project description

django-dbtemplates-iplweb

PyPI Tests Python Version Django Version License Documentation

dbtemplates is a Django app that stores templates in the database and exposes them through a regular Django template loader — so templates can be edited from the admin instead of being redeployed as files.

Originally developed by Jannis Leidel and Jazzband. This fork is actively maintained by IPLweb.

Support graciously provided by

IPLweb

Why?

Django's built-in template loaders read from the filesystem or app directories. That works well for developer-owned templates, but not for content that needs to change without a deploy (marketing copy, transactional email bodies, error pages, site-specific overrides). dbtemplates adds a loader that reads templates from a database model, so non-developers can edit them via the admin and changes take effect immediately.

Features

  • Database-backed Django template loader — drop-in with the standard TEMPLATES.OPTIONS.loaders chain
  • Edit templates through the Django admin (syntax highlighting included)
  • Multi-site support via django.contrib.sites — the same template name can resolve to different content per site
  • Cache integration with Django's cache framework; invalidation on save
  • Management commands:
    • sync_templates — bidirectional sync between the database and filesystem templates
    • check_template_syntax — validate all stored templates
    • create_error_templates — scaffold 404.html / 500.html rows
  • Admin actions and optional versioned storage

Supported versions

Python

3.10 3.11 3.12 3.13

Django

Django \ Python 3.10 3.11 3.12 3.13
4.2 LTS
5.0
5.1
5.2

Matrix derived from tox.ini and Django's own Python support matrix. djmain (Django's unreleased main branch) is tested against Python 3.12 / 3.13.

Installation

Using uv (recommended)

uv add django-dbtemplates-iplweb

Using pip

pip install django-dbtemplates-iplweb

The Python import name stays dbtemplates, so no code changes are needed when migrating from upstream django-dbtemplates:

from dbtemplates.models import Template

From git (latest master)

uv add "git+https://github.com/mpasternak/django-dbtemplates-iplweb.git"
# or
pip install "git+https://github.com/mpasternak/django-dbtemplates-iplweb.git"

Quick start

  1. Add dbtemplates to INSTALLED_APPS alongside django.contrib.sites and django.contrib.admin:

    INSTALLED_APPS = [
        "django.contrib.auth",
        "django.contrib.contenttypes",
        "django.contrib.sessions",
        "django.contrib.sites",
        "django.contrib.admin",
        "dbtemplates",
    ]
    
  2. Add dbtemplates.loader.Loader to TEMPLATES.OPTIONS.loaders:

    TEMPLATES = [
        {
            "BACKEND": "django.template.backends.django.DjangoTemplates",
            "OPTIONS": {
                "loaders": [
                    "django.template.loaders.filesystem.Loader",
                    "django.template.loaders.app_directories.Loader",
                    "dbtemplates.loader.Loader",
                ],
            },
        },
    ]
    

    Put dbtemplates.loader.Loader last to use database templates as a fallback, or first to let them override on-disk templates.

  3. Apply migrations and start the server:

    python manage.py migrate
    python manage.py runserver
    
  4. Open the admin, go to Database templates → Templates, and create entries with a name (e.g. blog/entry_list.html) and template content.

See https://django-dbtemplates.readthedocs.io/ for the complete documentation.

Links

License

BSD — see LICENSE for details.

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_dbtemplates_iplweb-4.3.2.tar.gz (80.1 kB view details)

Uploaded Source

Built Distribution

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

django_dbtemplates_iplweb-4.3.2-py3-none-any.whl (86.8 kB view details)

Uploaded Python 3

File details

Details for the file django_dbtemplates_iplweb-4.3.2.tar.gz.

File metadata

File hashes

Hashes for django_dbtemplates_iplweb-4.3.2.tar.gz
Algorithm Hash digest
SHA256 32e2913e48784b1d004a44341bc34a7202117d474099a13adb757a1ad4e10e5d
MD5 2eeaad50b7692a62b6ee055ec6b3fd66
BLAKE2b-256 588968a7161426db8837dd7fea0607f63eb2e45c147726544395221f2344c985

See more details on using hashes here.

File details

Details for the file django_dbtemplates_iplweb-4.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_dbtemplates_iplweb-4.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0e3290ed15f5a2c797e72936d8d1f4d06dd7155409183c0af769e532013737d2
MD5 58bb47832b8f030b29dbce6f84c15f4b
BLAKE2b-256 18f23c3e2b5117e351a1aa0a5a888044e2ebfb85f193036ea9fbc81fbb001015

See more details on using hashes here.

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