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. My firs Snippets by GutemaG 19 hours, 1 minute ago
  2. FileField having auto upload_to path by junaidmgithub 1 month, 1 week ago
  3. LazyPrimaryKeyRelatedField by LLyaudet 1 month, 2 weeks ago
  4. CacheInDictManager by LLyaudet 1 month, 2 weeks ago
  5. MYSQL Full Text Expression by Bidaya0 1 month, 2 weeks ago

Comments

Please login first before commenting.