From d08407291a209bcdda96fa63e3cb9abca8ab937a Mon Sep 17 00:00:00 2001
From: tommy3001
Date: Mon, 29 Jul 2013 14:18:20 +0200
Subject: [PATCH 1/4] entry about different tutorials added
---
Readme.rst | 1 +
1 file changed, 1 insertion(+)
diff --git a/Readme.rst b/Readme.rst
index a789e7fee..b0e60c62c 100644
--- a/Readme.rst
+++ b/Readme.rst
@@ -26,6 +26,7 @@ Topics include:
- Testing. Jenkins + tox guides.
- How to interface w/ hg from git easily
- what libraries to use for what
+- Different tutorials
If you are not fond of reading reStructuredText, there is an
almost up-to-date `HTML version at docs.python-guide.org
From 60cdeae7f7e4d1cfb4d3dd9428b13ce667b0c44a Mon Sep 17 00:00:00 2001
From: tommy3001
Date: Tue, 30 Jul 2013 10:37:24 +0200
Subject: [PATCH 2/4] Tornado web server and Jinja2 template engine with
example added
---
docs/scenarios/web.rst | 130 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 130 insertions(+)
diff --git a/docs/scenarios/web.rst b/docs/scenarios/web.rst
index 1520b4bbc..2093c15cc 100644
--- a/docs/scenarios/web.rst
+++ b/docs/scenarios/web.rst
@@ -90,6 +90,15 @@ application that is not commonly found in other web frameworks.
Support can be found on its `mailing list `_.
+Tornado
+--------
+`Tornado `_ is a scalable, non-blocking web server and web application framework with
+a relative simple usage. Tornado is known for his high performance.
+It was initially developed for `friendfeed `_ , a real time chat and blog system.
+
+In the Jinja2 template engine example it is used to serve the rendered pages.
+
+
Pyramid
--------
@@ -269,6 +278,127 @@ and to the templates themselves.
the parts where the HTML template passes some variable content
to the javascript code.
+
+
+Jinja2
+------
+`Jinja2 `_ is a template engine which is similar to the Django template system with some extra features. It is a text-based template
+language and thus can be used to generate any markup. It allows customization of filters, tags, tests and globals.
+Unlike the template system implemented in the Django Framework it allows to call functions. The Code is staying under the BSD license.
+
+Here some important html tags in jinja2:
+
+.. code-block:: html
+
+ {# This is a comment #}
+ {# The next tag is a variable output: #}
+ {{title}}
+ {# Tag for a block, can be replaced through inheritance with other html code #}
+ {% block head %}
+
I'm the head!
+ {% endblock %}
+ {# Output of an array as an iteration #}
+ {% for item in list %}
+
{{ item }}
+ {% endfor %}
+
+
+
+The next listings is an example of a web site in combination with the tornado web server. Tornado is not very complicate
+to use.
+
+.. code-block:: python
+
+ from jinja2 import Environment, FileSystemLoader
+ TEMPLATE_FILE = "site.html"
+ templateLoader = FileSystemLoader( searchpath="templates/" )
+ templateEnv = Environment( loader=templateLoader )
+ template = templateEnv.get_template(TEMPLATE_FILE)
+ import tornado.ioloop
+ import tornado.web
+ #import jinja2
+ from jinja2 import Environment, FileSystemLoader
+ #load tamplate file templates/site.html
+ TEMPLATE_FILE = "site.html"
+ templateLoader = FileSystemLoader( searchpath="templates/" )
+ templateEnv = Environment( loader=templateLoader )
+ template = templateEnv.get_template(TEMPLATE_FILE)
+ #import tornado
+ import tornado.ioloop
+ import tornado.web
+ #list for famous movie rendering
+ movie_list = [[1,"The Hitchhiker's Guide to the Galaxy"],[2,"Back to future"],[3,"Matrix"]]
+
+ # template.render() returns a string which contains the rendered html
+ html_output = template.render(list=movie_list,
+ title="Here is my favorite movie list")
+
+ #Handler for main page
+ class MainHandler(tornado.web.RequestHandler):
+ def get(self):
+ #returns rendered template string to the browser request
+ self.write(html_output)
+
+ # Assign handler to the server root (127.0.0.1:PORT/)
+ application = tornado.web.Application([
+ (r"/", MainHandler),
+ ])
+ PORT=8884
+ if __name__ == "__main__":
+ # Setup the server
+ application.listen(PORT)
+ tornado.ioloop.IOLoop.instance().start()
+
+The `base.html` file can be used as base for all site pages which are for example implemented in the content block.
+
+.. code-block:: html
+
+
+
+
+
+
+ {{title}} - My Webpage
+
+
+
+ {# In the next line the content from the site.html template will be added #}
+ {% block content %}{% endblock %}
+
+
+
+
+
+The next listing is our site page (`site.html`) loaded in the python app which extends `base.html`. The content block is automatically
+set into the corresponding block in the base.html page.
+
+.. code-block:: html
+
+
+
+
{{title}}
+
{{ list_title }}
+
+ {% for item in list %}
+
{{ item[0]}} : {{ item[1]}}
+ {% endfor %}
+
+
+
+ {% endblock %}
+
+
+
+
+
+
+
.. rubric:: References
.. [1] `The mod_python project is now officially dead `_
From f7d35dafa7f019a54c2a50619a5f151c8238f7f3 Mon Sep 17 00:00:00 2001
From: tommy3001
Date: Tue, 30 Jul 2013 11:17:54 +0200
Subject: [PATCH 3/4] Review of Jinja2 template system and tornado webserver
Some issues found
---
Readme.rst | 1 -
1 file changed, 1 deletion(-)
diff --git a/Readme.rst b/Readme.rst
index b0e60c62c..a789e7fee 100644
--- a/Readme.rst
+++ b/Readme.rst
@@ -26,7 +26,6 @@ Topics include:
- Testing. Jenkins + tox guides.
- How to interface w/ hg from git easily
- what libraries to use for what
-- Different tutorials
If you are not fond of reading reStructuredText, there is an
almost up-to-date `HTML version at docs.python-guide.org
From cee6b239aa6a21edc4aed2816d15b9066a88b51f Mon Sep 17 00:00:00 2001
From: tommy3001
Date: Tue, 30 Jul 2013 11:31:15 +0200
Subject: [PATCH 4/4] Tornado web server and Jinja2 template engine with
example added
---
docs/scenarios/web.rst | 38 ++++++++++++++++----------------------
1 file changed, 16 insertions(+), 22 deletions(-)
diff --git a/docs/scenarios/web.rst b/docs/scenarios/web.rst
index 2093c15cc..32a0ce231 100644
--- a/docs/scenarios/web.rst
+++ b/docs/scenarios/web.rst
@@ -286,17 +286,20 @@ Jinja2
language and thus can be used to generate any markup. It allows customization of filters, tags, tests and globals.
Unlike the template system implemented in the Django Framework it allows to call functions. The Code is staying under the BSD license.
-Here some important html tags in jinja2:
+Here some important html tags in Jinja2:
.. code-block:: html
{# This is a comment #}
+
{# The next tag is a variable output: #}
{{title}}
+
{# Tag for a block, can be replaced through inheritance with other html code #}
{% block head %}
-
I'm the head!
+
This is the head!
{% endblock %}
+
{# Output of an array as an iteration #}
{% for item in list %}
{{ item }}
@@ -309,34 +312,30 @@ to use.
.. code-block:: python
+ # import Jinja2
from jinja2 import Environment, FileSystemLoader
- TEMPLATE_FILE = "site.html"
- templateLoader = FileSystemLoader( searchpath="templates/" )
- templateEnv = Environment( loader=templateLoader )
- template = templateEnv.get_template(TEMPLATE_FILE)
+
+ # import Tornado
import tornado.ioloop
import tornado.web
- #import jinja2
- from jinja2 import Environment, FileSystemLoader
- #load tamplate file templates/site.html
+
+ # Load tamplate file templates/site.html
TEMPLATE_FILE = "site.html"
templateLoader = FileSystemLoader( searchpath="templates/" )
templateEnv = Environment( loader=templateLoader )
template = templateEnv.get_template(TEMPLATE_FILE)
- #import tornado
- import tornado.ioloop
- import tornado.web
- #list for famous movie rendering
+
+ # List for famous movie rendering
movie_list = [[1,"The Hitchhiker's Guide to the Galaxy"],[2,"Back to future"],[3,"Matrix"]]
# template.render() returns a string which contains the rendered html
html_output = template.render(list=movie_list,
title="Here is my favorite movie list")
- #Handler for main page
+ # Handler for main page
class MainHandler(tornado.web.RequestHandler):
def get(self):
- #returns rendered template string to the browser request
+ # Returns rendered template string to the browser request
self.write(html_output)
# 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
-The next listing is our site page (`site.html`) loaded in the python app which extends `base.html`. The content block is automatically
-set into the corresponding block in the base.html page.
+The next listing is our site page (`site.html`) loaded in the python app which extends `base.html`. The content block is
+automatically set into the corresponding block in the base.html page.
.. code-block:: html
@@ -394,11 +393,6 @@ set into the corresponding block in the base.html page.
{% endblock %}
-
-
-
-
-
.. rubric:: References
.. [1] `The mod_python project is now officially dead `_