Skip to main content

A Django fitemplate field twith managers to return the rendered or unrendered template.

Project description

A Django template field with a manager to return the rendered template.


The full documentation is at


Install django-template-field:

pip install django-template-field

Then use it in a project:

from django.db import models

from templatefield import fields, managers

class TemplatedText(models.Model):
    value = fields.TemplateTextField()

    # Manager that returns rendered templates. This will be the default
    # manager since it is first. Now, when accessed via `Related Models`_
    # this field will also be rendered.
    objects_rendered = managers.RenderTemplateManager()
    # Django's default manager returns unrendered templates.
    objects_unrendered = models.Manager()

Extra context can be added in settings like so:

TEMPLATE_FIELD_CONTEXT = { ‘template_var’: value }

Context can also be added to querysets like so:

TemplatedText.objects_rendered.with_context({‘template_var2’: value2})

If you dump fixtures with RenderTemplateManager as the default manager, django will render the exported data. To work around that, create an alternate settings file for your project with the following setting:


Then you can dump your unrendered data like so:

./ dumpdata myapp.mymodel –settings=myapp.dump_settings


Using RenderTemplateManager as the default has the unfortunate side effect of rendering your fields in the Django admin, so we have provided a class from which you can inherit to solve that problem. Ex:

from templatefield import admin

class TemplatedTextAdmin(admin.UnrenderedAdmin):

Running Tests

source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install -r requirements/test.txt (myenv) $ python


0.3.1 (2016-01-11)

  • Add setting to disable rendering

0.3.0 (2016-01-06)

  • Enable rendering in related field access

0.2.0 (2015-10-23)

  • Add with_context to RenderTemplateManager

0.1.0 (2015-10-02)

  • First release on PyPI.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-template-field, version 0.3.1
Filename, size File type Python version Upload date Hashes
Filename, size django-template-field-0.3.1.tar.gz (7.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page