Source

django-in-a-box / docs / wiki / tools / jinja2.md

Jinja2

Jinja2 is a fast and simple templating system for Python. It has a syntax based on Django’s built-in templating system, but gives you a bit more expressive power and flexibility. With this power, however, comes responsibility; you should always try to constrain your heavy business logic to your view functions.

Nevertheless, if you use it right, it can be a powerful tool and can save you a lot of time and effort working around the constraints of the Django’s built-in templating system. Anyone who has ever had to type {% endifnotequal %} knows what that means.

DjanJinja

In order to integrate more closely with Jinja2, Django-in-a-Box includes DjanJinja, a Django application which provides several shortcuts and wrappers to make using Jinja2 feel more native within Django. To get started straight away, write your templates using Jinja2, putting them in the same location as usual. To render them from within your views:

from djanjinja.views import render_to_response

def myview(request):
    return render_to_response('template_name.txt', {'key': 'value'})

For more information, consult the DjanJinja documentation at its project page.

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 ProjectModifiedEvent.java.
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.