Show Menu
Cheatography

Jinja 2 template syntax Cheat Sheet (DRAFT) by

Syntaxe des templates Jinja 2

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Délimi­teurs

{{ Variable }}
{{ Var.attrib }}
{{ Var['a­ttrib'] }}
{{ Variable | filtre | ... }}
{% Controle %}
{# Commen­taires #}

Controles

for else endfor
loop.xxx
if elif else endif
macro endmacro
call
filter endfilter
set
set block endset
include
ignore missing
import
from import as

Opérateurs

+
-
/
//
%
*
**
==
!=
>
>=
<
<=
and
or
not
(expr)
in
is
|
~
./[]
foo.bar
foor['­bar']

Espaces

{%-
-%}
supprime espaces avant ou après
{%+
 

Filtre Chaines

capita­lize(s)
center(value,­width)
escape(s)
forcee­scape(value)
format(value,­*ar­gs,­**k­wargs))
indent(s,widt­h=4­,in­den­tfi­rst­=False)
lower(s)
upper(s)
pprint(value,­ver­bos­e=False)
replace(s,old,­new­,co­unt­=None)
string(object)
striptags(value)
title(s)
trim(value)
urlencode(value)
urlize(value,­tri­m_u­rl_­lim­it,­nof­oll­ow,­target)
wordcount(s)
xmlattr(d,auto­spa­ce=True)

Filtre Nombres

abs(number)
random(seq)
int(value,­def­ault=0)
float(value,­def­aul­t=0.0)
sum(iterab­le,­att­rib­ute­=No­ne,­start=0)

Héritage

block name
endblock
extends "­tem­plf­ile­"
self.name
super()
Les
endblock
peuvent être nommés

Global

range(start,­sto­p,step)
libsum(n=5,ht­ml=­Tru­e,m­in=­20,­max=100)
dict(**items)
class cylcler(*items
reset()
next()
current
class joiner(sep=',')
 

Filtre Divers

attr(obj,name)
reject­attr()
default(value,­def­aul­t,b­ool­ean­=False)
|
d
filesi­zef­ormat(value, binary­=False)
safe(value)
select()
select­attr()
Utilisé dans
{{ Variable | filtre | ... }}
ou dans les commandes

Filtre Liste

dicsort(value,­cas­e_s­ens­iti­ve=­Fal­se,­by=­'key'))
first(seq)
last(seq)
groupby(value,attr)
map()
join(value,­d='­u',­att­rib­ute­=None)
lenght(object)
llist(value)
reverse(value)
select()
select­attr()
slice(value,­sli­ces­,fi­lle­_wi­th=None)
sort(value,­rev­ers­e,c­ase­_se­nsi­sti­ve,­att­ribute)
sum(iterab­le,­att­rib­ute­=No­ne,­start=0)

Tests

callable(object)
divisi­bleby(value,num)
escaped(value)
mapping(value)
iterable(value)
sequence(value)
string(value)
number(value)
lower(value)
upper(value)
defined(value)
undefined(value)
none(value)
even(value)
odd(value)
equalto(value,­other)
sameas(value)