Skip to main content

Jinja2 templating language integrated in Django.

Project description

Django application for integrating jinja2 template system.

Jinja2 provides certain advantages over the native system of django, for example, explicit calls to callable from templates, has more performance and has a plugin system, etc …

There is another project like this: Djinja. Unlike him, django-jinja is not intended to replace the django templates, but it complements the django templates, giving the possibility to use both. Thus no need to adapt applications to use django jinja2 only use it where you need it.

Another advantage of “django-jinja” is that you can still use django as before, regardless of specific helper or specific shortcuts.

Features:

  • Auto load templatetags compatible with jinja2

  • Can combine django templates with jinja2 templates.

  • A lot of django template filters ported for work with jinja2

How to install?

You can download tarball from <http://pypi.python.org/pypi/django-jinja/>, extract this and install with:

tar xvf django-jinja-x.y.tar.gz
cd django-jinja
python setup.py install

Other alternative is install with pip:

pip install django-jinja

How to use this on your django project?

As a first and only step, you have to replace django template_loaders by django-jinja2 loaders:

# settings.py
TEMPLATE_LOADERS = (
    'django_jinja.loaders.AppLoader',
    'django_jinja.loaders.FileSystemLoader',
)

INSTALLED_APPS += ('django_jinja',)

Now you can place templates (“.jinja” extension) as you would with normal django templates.

You can specify the default extension for jinja2 by the parameter DEFAULT_JINJA2_TEMPLATE_EXTENSION in settings.py:

# settings.py
DEFAULT_JINJA2_TEMPLATE_EXTENSION = '.jinja'

You can also assign different options to the Environment by JINJA2_ENVIRONMENT_OPTIONS parameter. To see more details, please see the sample application.

Additionally you can specify whether or not to activate Autoescape extension with JINJA2_AUTOESCAPE boolean parameter. By default is desactivated.

Django filters and functions:

Url reverse:

Useful for reverse urls on templates. Currently have two alternatives: filter or function.

Usage examples:

{{ 'ns:urlaname'|reverse(arg1=val1) }}
{{ url('ns:urlaname', arg1=val1) }}

Almost all of django templatefilters are available in “django-jinja”, and if you find one at fault, patches are welcome.

I18N and Django gettext

django-jinja incorporates an extension to makemessages command, so you can deal with differences of translations jinja tags.

This is an example of use:

python ../manage.py makemessages  -a -e py,jinja,html

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-jinja-0.9.tar.gz (8.1 kB view details)

Uploaded Source

File details

Details for the file django-jinja-0.9.tar.gz.

File metadata

  • Download URL: django-jinja-0.9.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-jinja-0.9.tar.gz
Algorithm Hash digest
SHA256 8e77146d8030132a34da4b3e0842baf0397ddd5de90eb5365ae2acf9e87af4df
MD5 0c6814d2224e2f0d58cf8c02568fd53d
BLAKE2b-256 1c7d3de5835f558b162e06deba9f55c17e4d0271b313aa70669081a08fd3ca13

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