Using Jinja2 in Django with Coffin: The Easy Way

pThere is stronga lot/strong of old, incorrect and just plain bad documentation on how to use the a href="http://jinja.pocoo.org/docs/"Jinja2 templating language/a in a href="https://www.djangoproject.com/"Django/a. Here#8217;s how to do it strongThe Easy Way/strong./p

ollipInstall Jinja2, a href="http://pygments.org/"Pygments/a and a href="https://github.com/coffin/coffin"Coffin/a with codeeasy_install Jinja2 Pygments Coffin/code or by editing your a href="http://www.pip-installer.org/en/latest/requirements.html"Pip requirements.txt file/a./p/li
lipIn codeviews.py/code, change:/p

precodefrom django.shortcuts import render_to_response
/code/pre

pto:/p

precodefrom coffin.shortcuts import render_to_response
/code/pre

pa href="https://github.com/coffin/coffin#rendering"as described in the Coffin docs/a./p/li
lipa href="http://jinja.pocoo.org/docs/switching/#django"Update your templates to use Jinja2 syntax/a. Change codeblock.super/code to codesuper()/code./p/li
lipIf you use code{% compress %}/code tags, add:/p

precodeJINJA2_EXTENSIONS = [
'compressor.contrib.jinja2ext.CompressorExtension',
]
/code/pre

pto your codesettings.py/code a href="http://django_compressor.readthedocs.org/en/latest/jinja2/#for-coffin-users"as described here/a./p/li
/olimg src="http://feeds.feedburner.com/~r/slashpoundbang/RQTZ/~4/3DKlhAbuARE" height="1" width="1"/