Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example gravatar implementation for Python 2 *and* 3, using libgravatar
# For just python:
pip install libgravatar
# libravatar documentation/options at:
# Then:
from libgravatar import Gravatar
g = Gravatar('')
# (returns working URL to gravatar image)
# ----------
# For Django (as a template tag/filter), in file templatetags/
def gravatar(email, size=40):
'''Get commenter's avatar from Gravatar service via API'''
g = Gravatar(email)
return g.get_image(size, "mm")
# Then in your templates:
{% load mytags %}
{# Replace number with preferred dimensions. #}
<img src="{{|gravatar:60 }}" alt="" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment