Skip to main content

Jinja2 template renderer for Django

Project description

Cofingo is a combination of Coffin (http://github.com/coffin/coffin) and Jingo (http://github.com/jbalogh/jingo). It allows the usage of Jinja2 templates while keeping the tags and filters from Django (e.g. the URL tag)

Like Jingo the way to add custom filters, tags (extensions), and tests is by creating a helpers.py file in your app.

Getting started

The easiest way to install Cofingo is by using pip:

pip install cofingo

The development version can be found at:

http://github.com/mvantellingen/cofingo

Configuration

Add cofingo.Loader to your settings:

TEMPLATE_LOADERS = (
    'cofingo.Loader',
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

Templates are then rendered by Jinja2 whichever method is used (It works for class based views, TemplateResponse etc).

If you want to prevent that the templates of a specific app are rendered with Jinja2 then you can excluded them in your settings file:

COFINGO_EXCLUDED_APPS = ['admin', 'debug_toolbar']

(Note that these two apps are added by default)

Creating custom filters and extensions

Create a helpers module in your django app and add the following:

from cofingo.library import Library

library = Library()

If you want to add a filter add the following:

@library.filter
def my_custom_filter(value):
    return value + '-filtered'

Adding an extension can be done as follow:

from cofingo.library import Library
from django_assets.env import get_env
from webassets.ext.jinja2 import AssetsExtension

library = Library()
library.attr('assets_environment', get_env())
library.extension(AssetsExtension)

You can also add other modules with a library to Cofingo by specifying them in your settings.py file:

COFINGO_HELPERS = [
    'myproject.helpers'
]

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-cofingo-0.1.0.tar.gz (15.5 kB view details)

Uploaded Source

File details

Details for the file django-cofingo-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django-cofingo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2b775aa1e2e8e8e5f250306e8c4fb0dd6ab0f080172dfe3d824d918cdf148382
MD5 2b6a94880df229de1e217e06b59226fb
BLAKE2b-256 fe6403c7fdd9a449a38d6acac5ab7590121b1a98ed727da2bc74b2ef35f4f0b9

See more details on using hashes here.

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