Tornado web server

PyWeb-IL 29

http://www.tornadoweb.org/

Buzzwords galore

Meta

Hello PyWeb

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello PyWeb")

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()

Asynchronous

tornado.web.asynchronous

When used, request is done when finish is called.

URL = 'http://www.bankisrael.gov.il/currency.xml'

class CurrencyHandler(tornado.web.RequestHandler):
    @tornado.web.asynchronous
    def get(self):
       http = httpclient.AsyncHTTPClient()
       http.fetch(URL, self._got_currency)

    def _got_currency(self, response):
       self.write(response.body)
       self.finish()

Non blocking DB calls ?

Web application server

Core web framework

Templates

Templates custom functions

Can pass custom functions like variables.

python

def add(x, y):
   return x + y
template.execute(add=add)

template

{{ add(1, 2) }}

Brownie points

tornado.auth

Closing time

Contact
Meir Kriheli <mkriheli@gmail.com>