Skip to content
Browse files

Add another demo app

  • Loading branch information...
1 parent 1360e34 commit 181eb083127aeff7d72501033694f8e5124df785 @rcmachado rcmachado committed Sep 7, 2012
View
2 README.rst
@@ -26,6 +26,8 @@ directory of your app:
$ torneira --port 8888 --settings settings.py
In the directory `demos/simple_app/` there is a minimal app already configured.
+If you want to see a more complex app that uses more available features, take a
+look at `demos/more_complex_app`.
Contributing
------------
View
0 demo/more_complex_app/__init__.py
No changes.
View
23 demo/more_complex_app/handlers.py
@@ -0,0 +1,23 @@
+# coding: utf-8
+from tornado.web import asynchronous
+from torneira import __version__
+from torneira.handler import TorneiraHandler
+from torneira.template import MakoMixin
+
+
+class MainHandler(TorneiraHandler, MakoMixin):
+ def index(self):
+ return self.render_to_template('index.html')
+
+ def simple(self):
+ return "You can use self.write or just returns the contents"
+
+ def as_json(self):
+ return {'json_response': [1, 2, 3]}
+
+ @asynchronous
+ def async(self):
+ context = {'version': __version__}
+ content = self.render_to_template('async.html', **context)
+ self.write(content)
+ self.finish()
View
12 demo/more_complex_app/settings.py
@@ -0,0 +1,12 @@
+import os
+from functools import partial
+
+
+ROOT_URLS = 'more_complex_app.urls'
+DEBUG = True
+
+join = partial(os.path.join, os.path.dirname(__file__))
+
+TEMPLATE_DIRS = (
+ join('templates'),
+)
View
12 demo/more_complex_app/templates/async.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Sample Torneira App</title>
+ </head>
+ <body>
+ <h1>Async Handler</h1>
+
+ <p>This is a template rendered on an async request.</p>
+ </body>
+</html>
View
19 demo/more_complex_app/templates/index.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Sample Torneira App</title>
+ </head>
+ <body>
+ <h1>Torneira</h1>
+
+ <p>This is a simple template, rendered using <a href="http://www.makotemplates.org/">Mako template engine</a></p>
+
+ <ul>
+ <li><a href="/">This page</a></li>
+ <li><a href="/simple">Simple response - no template!</a></li>
+ <li><a href="/async">Async handler + mako template</a></li>
+ <li><a href="/json">We can speak JSON too!</a></li>
+ </ul>
+ </body>
+</html>
View
12 demo/more_complex_app/urls.py
@@ -0,0 +1,12 @@
+# coding: utf-8
+from tornado.web import url
+
+from more_complex_app.handlers import MainHandler
+
+
+urls = (
+ url(r'/', MainHandler, {'action': 'index'}),
+ url(r'/simple', MainHandler, {'action': 'simple'}),
+ url(r'/json', MainHandler, {'action': 'as_json'}),
+ url(r'/async', MainHandler, {'action': 'async'}),
+)

0 comments on commit 181eb08

Please sign in to comment.
Something went wrong with that request. Please try again.