django-pipeline + django-jinja

04 October 2015   2 comments   Django

Do you have django-jinja in your Django 1.8 project to help you with your Jinja2 integration, and you use django-pipeline for your static assets?
If so, you need to tie them together by passing pipeline.templatetags.ext.PipelineExtension "to your Jinja2 environment". But how? Here's how:

# in your settings.py


from django_jinja.builtins import DEFAULT_EXTENSIONS

TEMPLATES = [
    {
        'BACKEND': 'django_jinja.backend.Jinja2',
        'APP_DIRS': True,
        'OPTIONS': {
            'match_extension': '.jinja',
            'context_processors': [
                ...
            ],
            'extensions': DEFAULT_EXTENSIONS + [
                'pipeline.templatetags.ext.PipelineExtension',
            ],
        }
    },
    ...

Now, in your template you simply use the {% stylesheet '...' %} or {% javascript '...' %} tags in your .jinja templates without the {% load pipeline %} stuff.

It took me a little while to figure that out so I hope it helps someone else googling around for a solution alike.

Comments

Asif
Why you are using django_jinja when there is built in support for jinja2 template from django 1.8+?
Peter Bengtsson
I honestly can't remember now. The documentation lists its features: http://niwinz.github.io/django-jinja/

The reason I use it is because I built my project from Sugardough https://github.com/mozilla/sugardough which is the Mozilla Django best practice project.

Your email will never ever be published


Related posts

Previous:
Using Lovefield as an AJAX proxy maybe 30 September 2015
Next:
localStorage is not async, but it's FAST! 06 October 2015
Related by Keyword:
Find static files defined in django-pipeline but not found 25 July 2017
How to no-mincss links with django-pipeline 03 February 2016
Related by Text:
jQuery and Highslide JS 08 January 2008
I'm back! Peterbe.com has been renewed 05 June 2005
Anti-McCain propaganda videos 12 August 2008
I'm Prolog 01 May 2007
Ever wondered how much $87 Billion is? 04 November 2003