Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!


This field is used for storing template-strings in database.

You can't just store django.template.Template() in the field, because we can't
convert it back to the string. Please store a string with template instead, it
will be converted to the Template() automagically.


1. Add templatefield/ directory to your python import path (for example, copy it
into the directory with your other apps).

2. Define a form with a template, like:

from templatefield.fields import TemplateField

class Widget(models.Model):
    template = TemplateField()

3. In the admin, in the form, in the shell or in your app code you can save
any template string to this field:

>>> from my_app.models import Widget
>>> w = Widget(template="Hello, {{ username }}!")
>>> w.template
<templatefield.fields.StoredTemplate object at 0x2bc0f50>


4. Render a template as your usual Template:
>>> from django.template import Context
>>> w.template.render(Context({'username': 'Bob Marley'}))
u'Hello, Bob Marley!'

Recent activity

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.