Gravator Technology

This is code debugging website.

 

import hashlib
import urllib
from django import template
from django.utils.safestring import mark_safe

register = template.Library()

# return only the URL of the gravatar
# TEMPLATE USE:  {{ email|gravatar_url:150 }}
@register.filter
def gravatar_url(email, size=40):
default = “https://example.com/static/images/defaultavatar.jpg”
return “https://www.gravatar.com/avatar/%s?%s” % (hashlib.md5(email.lower()).hexdigest(), urllib.urlencode({‘d’:default, ‘s’:str(size)}))

# return an image tag with the gravatar
# TEMPLATE USE:  {{ email|gravatar:150 }}
@register.filter
def gravatar(email, size=40):
url = gravatar_url(email, size)
return mark_safe(‘<img src=”%s” height=”%d” width=”%d”>’ % (url, size, size))

Advertisements

One thought on “Gravator Technology

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s