piranha gto test cat py from jinja2 import Environment FileSystemLoade

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
piranha@gto 1 ~/test> cat j.py
from jinja2 import Environment, FileSystemLoader, ext, nodes
class MediaExt(ext.Extension):
tags = ['media']
def parse(self, parser):
parser.stream.next()
args = parser.parse_expression()
return [nodes.Const('test')]
loader = FileSystemLoader('.')
env = Environment(loader=loader, extensions=[MediaExt])
t = env.get_template('tmpl.html')
if __name__ == '__main__':
print t.render()
piranha@gto ~/test> cat tmpl.html
{% media 'test' %}
piranha@gto ~/test> python j.py
Traceback (most recent call last):
File "j.py", line 15, in <module>
t = env.get_template('tmpl.html')
File "/usr/local/Cellar/EasyInstall/2.6/lib/python2.6/site-packages/jinja2/environment.py", line 504, in get_template
template = self.loader.load(self, name, self.make_globals(globals))
File "/usr/local/Cellar/EasyInstall/2.6/lib/python2.6/site-packages/jinja2/loaders.py", line 108, in load
code = environment.compile(source, name, filename)
File "/usr/local/Cellar/EasyInstall/2.6/lib/python2.6/site-packages/jinja2/environment.py", line 424, in compile
return compile(source, filename, 'exec')
File "./tmpl.html", line 6
if 0: yield None'test'
^
SyntaxError: invalid syntax