Login

Simply Gravatar Templatetags

Author:
agusmakmun
Posted:
January 10, 2017
Language:
Python
Version:
1.10
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. Template tag - list punctuation for a list of items by shapiromatron 3 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 3 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 10 months, 2 weeks ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 11 months ago
  5. Help text hyperlinks by sa2812 12 months ago

Comments

Please login first before commenting.