Skip to content

Instantly share code, notes, and snippets.

@addoull
Forked from sivy/01_myfilters.py
Created May 14, 2017 01:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save addoull/e42878b1dcbae1dd00c642b462603788 to your computer and use it in GitHub Desktop.
Save addoull/e42878b1dcbae1dd00c642b462603788 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...'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment