Created
November 21, 2017 18:27
-
-
Save shacker/f5b814762f373614653f10a2abbb658a to your computer and use it in GitHub Desktop.
Example gravatar implementation for Python 2 *and* 3, using libgravatar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For just python: | |
pip install libgravatar | |
# libravatar documentation/options at: | |
# http://libgravatar.readthedocs.io/ | |
# Then: | |
from libgravatar import Gravatar | |
g = Gravatar('[email protected]') | |
g.get_image() | |
# (returns working URL to gravatar image) | |
# ---------- | |
# For Django (as a template tag/filter), in file templatetags/mytags.py | |
@register.filter | |
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="{{ comment.email|gravatar:60 }}" alt="" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment