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

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for django-jinja-0.8.tar.gz
Algorithm Hash digest
SHA256 39979b19a0744f9068caab99ce90f7f4e22346397ff8ca5c26ea69f171c6a9e6
MD5 f8f6466f6fb8b1e7176bc1dd41548c65
BLAKE2b-256 0673e44947e2ff345dc57d9cbe561f8f7de7c3b46844835b8f142cf000743b45

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page