import hashlib
from django import template

register = template.Library()


@register.filter
def to_gravatar_url(email):
    return ('https://gravatar.com/avatar/%s?d=retro' %
            hashlib.md5((email or '').strip().lower()).hexdigest())

import hashlib
from django import template

register = template.Library()


@register.filter
def to_gravatar_url(email):
    return ('https://gravatar.com/avatar/%s?d=retro' %
            hashlib.md5((email or '').strip().lower().encode('utf-8')).hexdigest())

Fix gravatar hashing error on py3
Fix gravatar hashing error on py3

  import hashlib
  from django import template
  
  register = template.Library()
  
  
  @register.filter
  def to_gravatar_url(email):
      return ('https://gravatar.com/avatar/%s?d=retro' %
-             hashlib.md5((email or '').strip().lower()).hexdigest())
+             hashlib.md5((email or '').strip().lower().encode('utf-8')).hexdigest())
  
Fix gravatar hashing error on py3
## Code Before:
import hashlib
from django import template

register = template.Library()


@register.filter
def to_gravatar_url(email):
    return ('https://gravatar.com/avatar/%s?d=retro' %
            hashlib.md5((email or '').strip().lower()).hexdigest())

## Instruction:
Fix gravatar hashing error on py3
## Code After:
import hashlib
from django import template

register = template.Library()


@register.filter
def to_gravatar_url(email):
    return ('https://gravatar.com/avatar/%s?d=retro' %
            hashlib.md5((email or '').strip().lower().encode('utf-8')).hexdigest())
