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'http://gravatar.com/avatar/%s?s=%s.%s' 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 ...