- Author:
- jkocherhans
- Posted:
- March 3, 2007
- Language:
- Python
- Version:
- Pre .96
- Score:
- 12 (after 12 ratings)
Mask an email address by removing most of the first portion and replacing it with "..."
For example. If you have a variable in your template context named email_address
, and its value is "[email protected]"
{{ email_address|mask_email }}
will render as:
[email protected]
If the part preceding @domain.com is shorter than 5 characters, only the first letter will be used, followed by "...". So if we have "[email protected]"
{{ email_address|mask_email }}
will render as:
[email protected]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | from django import template
register = template.Library()
def mask_email(email):
"""Mask an email address."""
name, domain = email.split('@')
if len(name) > 5:
# show the first 3 characters
masked_name = name[:3]
else:
# just use the 1st character
masked_name = name[0]
return "%s...@%s" % (masked_name, domain)
register.filter('mask_email', mask_email)
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
- Help text hyperlinks by sa2812 1 year, 8 months ago
Comments
Best. Snippet. EVAR!
#
very nice. i added the filter to djazz
#
Please login first before commenting.