-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathapp.py
36 lines (27 loc) · 1012 Bytes
/
app.py
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
36
import tornado.template
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render("index.html")
class SubscribeHandler(tornado.web.RequestHandler):
def post(self):
name = self.get_argument('name', '')
template_data = """
Hello """+name+""",
Welcome to the {{company}} mailing-list.
"""
t = tornado.template.Template(template_data)
preview = t.generate(company="TornadeMedia")
self.render("subscribe.html", preview=preview)
class My404Handler(tornado.web.RequestHandler):
def prepare(self):
self.set_status(404)
self.render("404.html")
application = tornado.web.Application([
(r"/", MainHandler),
(r"/subscribe", SubscribeHandler),
], default_handler_class=My404Handler, debug=False, static_path='static', template_path='templates')
if __name__ == '__main__':
application.listen(80, address='0.0.0.0')
tornado.ioloop.IOLoop.instance().start()