Tornado – Escape – Json

Tornado web server exports methods for escape/unescape html, xml, Json among others. This blog discusses about encoding and decoding JSON format. Tornado has the following methods: tornado.escape.json_encode(value) - JSON'ify the Python object passed to it as argument tornado.escape.json_decode(value) - Converts the JSON string into Python Object Here's a usage example: https://gist.github.com/3478215 In this example, 1. … Continue reading Tornado – Escape – Json

Tornado – Database MySQL Client Wrapper

Tornado provides a simple MySQL wrapper for performing database operations. Class tornado.databse.Connection acts as a wrapper over MySQLdb DB-API connection. Consider you have a MySQL installed on your system and you create a DB 'mydb' with table 'post' and records as below: mysql> use mydb Database changed mysql> create table post (Id int, Title char(50), … Continue reading Tornado – Database MySQL Client Wrapper

Tornado – Asynchronous Requests

Tornado is a non-blocking I/O web server. In Tornado, when the request handler serves the request made by the client, the request is closed by itself. Python decorator @tornado.web.asynchronous can be used to override the default behavior (of automatically finishing the request) and keep the request open. So, its the duty of the server developer … Continue reading Tornado – Asynchronous Requests

Tornado – Error Handling

Web development often calls for gracefully handling of non-existent pages or broken links that users request for. A simple way to achieve error handling in Tornado is with: tornado.web.HTTPError - Exception handler that can used to generate error code of specified type. It is often used to raise an exception as we would see in … Continue reading Tornado – Error Handling

Tornado – Templates – Run time and Cached

Website development often calls for reuse of pages. For instance, when you open your Citibank account after login the welcome page you see is same what other bank customers see but its customized with your name and settings. Do you think Citi creates so many web pages for all its customers? Well, they use, what's … Continue reading Tornado – Templates – Run time and Cached