@@ -286,17 +286,20 @@ Jinja2
286286language and thus can be used to generate any markup. It allows customization of filters, tags, tests and globals.
287287Unlike the template system implemented in the Django Framework it allows to call functions. The Code is staying under the BSD license.
288288
289- Here some important html tags in jinja2 :
289+ Here some important html tags in Jinja2 :
290290
291291.. code-block :: html
292292
293293 {# This is a comment #}
294+
294295 {# The next tag is a variable output: #}
295296 {{title}}
297+
296298 {# Tag for a block, can be replaced through inheritance with other html code #}
297299 {% block head %}
298- <h1 >I'm the head!</h1 >
300+ <h1 >This is the head!</h1 >
299301 {% endblock %}
302+
300303 {# Output of an array as an iteration #}
301304 {% for item in list %}
302305 <li >{{ item }}</li >
@@ -309,34 +312,30 @@ to use.
309312
310313.. code-block :: python
311314
315+ # import Jinja2
312316 from jinja2 import Environment, FileSystemLoader
313- TEMPLATE_FILE = " site.html"
314- templateLoader = FileSystemLoader( searchpath = " templates/" )
315- templateEnv = Environment( loader = templateLoader )
316- template = templateEnv.get_template(TEMPLATE_FILE )
317+
318+ # import Tornado
317319 import tornado.ioloop
318320 import tornado.web
319- # import jinja2
320- from jinja2 import Environment, FileSystemLoader
321- # load tamplate file templates/site.html
321+
322+ # Load tamplate file templates/site.html
322323 TEMPLATE_FILE = " site.html"
323324 templateLoader = FileSystemLoader( searchpath = " templates/" )
324325 templateEnv = Environment( loader = templateLoader )
325326 template = templateEnv.get_template(TEMPLATE_FILE )
326- # import tornado
327- import tornado.ioloop
328- import tornado.web
329- # list for famous movie rendering
327+
328+ # List for famous movie rendering
330329 movie_list = [[1 ," The Hitchhiker's Guide to the Galaxy" ],[2 ," Back to future" ],[3 ," Matrix" ]]
331330
332331 # template.render() returns a string which contains the rendered html
333332 html_output = template.render(list = movie_list,
334333 title = " Here is my favorite movie list" )
335334
336- # Handler for main page
335+ # Handler for main page
337336 class MainHandler (tornado .web .RequestHandler ):
338337 def get (self ):
339- # returns rendered template string to the browser request
338+ # Returns rendered template string to the browser request
340339 self .write(html_output)
341340
342341 # Assign handler to the server root (127.0.0.1:PORT/)
@@ -373,8 +372,8 @@ The `base.html` file can be used as base for all site pages which are for exampl
373372 </body >
374373
375374
376- The next listing is our site page (`site.html `) loaded in the python app which extends `base.html `. The content block is automatically
377- set into the corresponding block in the base.html page.
375+ The next listing is our site page (`site.html `) loaded in the python app which extends `base.html `. The content block is
376+ automatically set into the corresponding block in the base.html page.
378377
379378.. code-block :: html
380379
@@ -394,11 +393,6 @@ set into the corresponding block in the base.html page.
394393 {% endblock %}
395394
396395
397-
398-
399-
400-
401-
402396.. rubric :: References
403397
404398.. [1 ] `The mod_python project is now officially dead <http://blog.dscpl.com.au/2010/06/modpython-project-is-now-officially.html >`_
0 commit comments