Login

Simply Gravatar Templatetags

Author:
agusmakmun
Posted:
January 10, 2017
Language:
Python
Version:
1.10
Tags:
django image templatetag gravatar
Score:
0 (after 0 ratings)

Simply Gravatar Templatetags, for example the name of this templatetag is: templatetags/gravatar_tags.py, this supported for Python2 or Python3.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
import hashlib
from django import template

try:
    # Python 3
    from urllib.parse import urlencode
except ImportError:
    from urllib import urlencode

register = template.Library()


@register.filter
def gravatar(email, size="75"):
    """
    {% load gravatar_tags %}
    {{ request.user.email|gravatar:"75" }}
    """
    gravatar_url = "//www.gravatar.com/avatar/" + \
        hashlib.md5(email.encode('utf-8')).hexdigest() + "?"
    gravatar_url += urlencode({'d': 'retro', 's': str(size)})
    return gravatar_url

More like this

Comments

Please login first before commenting.