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.0.tar.gz (80.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_dbtemplates_iplweb-4.3.0-py3-none-any.whl (86.7 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for django_dbtemplates_iplweb-4.3.0.tar.gz
Algorithm Hash digest
SHA256 af054d9cc783432b19dacc4e823cc5d3e0b43ff38200683b9348c9120133a937
MD5 1258c872fe91e0b26bb0ef3669ff843b
BLAKE2b-256 cc85d3f9ae64b6881fcae8c98a6b4fe01753928b2378249a4617e8f89261bb1a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_dbtemplates_iplweb-4.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5453079e999e36c011376b4b7ef768fef41ef95dca0764a6bd106b96c1e1e7ec
MD5 0c8bc4d8658d01094b4ae6a3f225cde6
BLAKE2b-256 f8f688111dfc94c77a5834d78f4bc852a52d69b6f273cbba12c12742bb7c6eb0

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