Posts

Showing posts with the label tornado

Tornado Web Framework - Flash Messages

Implement flash messages in Tornado web framework. Problem Suppose you have a URL for editing an object under /OBJECT-ID/edit . Normally when user fills in the information on that page and presses the submit button, the request is sent to /OBJECT-ID/update which persists the data. But if the the data provided by user is not valid, you need to redirect user the to /OBJECT-ID/edit along with the provided data and validation errors, so s/he can correct it. The clean and preferred way to do this is by using flash cookies. Code All the source code provided in this post, is licensed under Apache License 2.0. import re import pickle from tornado.escape import to_unicode from tornado import web, escape class Flash(object): """ A flash message along with optional (form) data. """ def __init__(self, message, data=None): """ 'message': A string. 'data': Can be anything. ""...