Greg Aker

Entries Tagged with: tornado

Tornado Gravatar Module

Filed in: tornado

February 16, 2011

Here's a quickie Gravatar UI Module for Tornado applications. It's simple, but you might find it useful.

import hashlib
import tornado.web

class Gravatar(tornado.web.UIModule):
    def render(self, email, size=40, image_type='jpg'):
        url = u''
        email_hash = hashlib.md5(email).hexdigest()
        return url % (email_hash, size, image_type)

Example Usage

{% for user in users %}
    <h2>{{ user['username'] }}</h2>
    <img src="{{ modules.Gravatar(username['email'], 40, 'jpg') }}" width="40" alt="{{ escape(user['username']) }}'s Avatar" >
{% end %}

It's totally simple and silly, but does cut down on a bit of repetitive code ...

Read More

MHT Setup in Tornado Applications

Filed in: tornado, web-dev

February 6, 2011

I've been working in Tornado a lot lately. If you don't know of it, it's a Python-based web server/framework written for Friend Feed which has since been open-sourced by Facebook.

The docs do a decent job getting you started, however, to really dig into the application you need to pour over the source code. As Mr. van Rossum says in PEP 8, code is read more often than it is written, and the FriendFeed/Facebook team has done a beautiful job with this application.

So there's a ton of ways to skin a cat in ...

Read More