a two-step dance with django and jinja2 templates

13
A Two-step Dance with Django and Jinja2 Templates Sebastien Mirolo @seabasscapoeira [email protected]

Upload: smirolo

Post on 16-Apr-2017

226 views

Category:

Software


0 download

TRANSCRIPT

A Two-step Dance with Django and Jinja2 TemplatesSebastien Mirolo@[email protected]

http://www.wpclipart.com/cartoon/people/angry_with_axe_2.png.html

Motivation

Where we started

80 template files4.3K lines of HTML template code+ Customers relyingon site to process payments

photo credit: Happip (http://www.flickr.com/photos/46629025@N02/5453823369) cc 2.0

The Plan

Deploy Django / Jinja2 compatible subsetFeature flag to toggle between template pipelines

An Easy Bit{% csrf_token %}

-{% csrf_token %}+{% block base_bodyscripts %}{% endblock %}{% endblock %}

$ cat index.html{% extends "base.html" %}

{% block bodyscripts %}{% block base_bodyscripts %}{{ block.super }}

{% endblock %}

Undefined Context Variables

{% if urls.profile %}My Profile{% endif %}

When everything can be solved with a filter$ cat templatetags/[email protected]()def is_authenticated(request): return hasattr(request, 'user') and request.user.is_authenticated()

$ cat index.html{% if request.user|is_authenticated %}...{% endif %}

is_authenticatedvs.is_authenticated()capfirstvs.capitalize

Moving Python code into Templatescrispy{% include with %} vs. {% macro %}

Moving Template code into PythonURL patterns{% if forloop.counter0|divisible_by:3 %} vs. {% if loop.index is divisibleby 3 %}

Jinja2 rendering pipeline quirksTemplate loadersCache dimensioningOptimizer in a multi-tier context

How you can help? Clone DjaoDjin repos and try them out!Star us on GitHub!

https://github.com/djaodjin/djaodjin-pages/https://github.com/djaodjin/djaodjin-saas/

Thank YouSebastien Mirolo@[email protected]