A Django template filter to protect email addresses from crawlers.
Install from the Python package index:
$ pip install django-email-obfuscator
Add email_obfuscator
to INSTALLED_APPS
in settings.py
:
INSTALLED_APPS = (
# ...
'email_obfuscator',
)
In your templates, you can protect email addresses with the obfuscate
filter:
{% load email_obfuscator %}
{{ '[email protected]'|obfuscate }}
The email address will be encoded with ASCII character entities, protecting it from spambots but rendering it readably in web browsers.
You can also use the filter to create clickable mailto
links:
{% load email_obfuscator %}
{{ '[email protected]'|obfuscate_mailto }}
#returns '<a href="mailto:[email protected]">[email protected]</a>' as an encoded string like
#<a href="mailto:your@email.com">your@email.com</a>
And if you want to add a custom link text, use this filter:
{% load email_obfuscator %}
{{ '[email protected]'|obfuscate_mailto:"my custom text" }}
#returns '<a href="mailto:[email protected]">my custom text</a>' as an encoded string like
#<a href="mailto:your@email.com">my custom text</a>
Joseph Mornin is the main author. Thanks to Benjamin Banduhn for optimizations and additions.