Skip to content

Instantly share code, notes, and snippets.

@sivy
Created March 1, 2012 21:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sivy/1953457 to your computer and use it in GitHub Desktop.
Save sivy/1953457 to your computer and use it in GitHub Desktop.
MD5 template filter for Django
from django import template
import hashlib
register = template.Library()
#
# {{ "some identifier"|md5 }}
# g87g98ht02497hg349ugh3409h34
#
@register.filter(name='md5')
def md5_string(value):
return hashlib.md5(value).hexdigest()
{% load myfilters %}
{% with "randstring"|add:user.email as email_key %}
user_hash: '{{ email_key|md5 }}'
{% endwith %}
outputs:
user_hash: 'snud763nwmf08nfn59qn3994nd...'
@addoull
Copy link

addoull commented May 14, 2017

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment