-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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'), | |||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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'}), | |||
) |