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

  1. "Magic Link" Management Command by webology 1 month, 3 weeks ago
  2. Closest ORM models to a latitude/longitude point by simonw 1 month, 3 weeks ago
  3. Log the time taken to execute each DB query by kennyx46 1 month, 3 weeks ago
  4. django database snippet by ItsRLuo 1 month, 4 weeks ago
  5. Serialize a model instance by chriswedgwood 2 months, 3 weeks ago

Comments

Please login first before commenting.