Advanced features


dbtemplates uses Django’s default caching infrastructure for caching, and operates automatically when creating, updating or deleting templates in the database.

To enable one of them you need to specify a setting called DBTEMPLATES_CACHE_BACKEND to one of the valid values Django’s CACHE_BACKEND can be set to. E.g.:



Starting in version 1.0 dbtemplates allows you also to set the new dict-based CACHES setting, which was introduced in Django 1.3.

All you have to do is to provide a new entry in the CACHES dict named 'dbtemplates', e.g.:

    'dbtemplates': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '',

Please see the cache documentation if you want to know more about it.

Versioned storage

dbtemplates comes prepared to use the third party Django app django-reversion, that once installed besides dbtemplates allows you to jump back to old versions of your templates. It automatically saves every state when you save the template in your database and provides an easy to use interface.

Please refer to django-reversion’s documentation for more information about how it works.


Just visit the “History” section of each template instance and browse its history.

Short installation howto

  1. Get the source from the django-reversion project site and put it somewhere on your PYTHONPATH.
  2. Add reversion to the INSTALLED_APPS setting of your Django project
  3. Sync your database with python syncdb
  4. Set DBTEMPLATES_USE_REVERSION setting to True

Management commands

dbtemplates comes with two Django management commands to be used with or

  • sync_templates

    Enables you to sync your already existing file systems templates with the database. It will guide you through the whole process.

  • create_error_templates

    Tries to add the two templates 404.html and 500.html that are used by Django when a error occurs.

  • check_template_syntax

    New in version 1.2.

    Checks the saved templates whether they are valid Django templates.

Admin actions

dbtemplates provides two admin actions to be used with Django>=1.1.

  • invalidate_cache

    Invalidates the cache of the selected templates by calling the appropriate cache backend methods.

  • repopulate_cache

    Repopulates the cache with selected templates by invalidating it first and filling then after that.

  • check_syntax

    New in version 1.2.

    Checks the selected tempaltes for syntax errors.