Skip to content

Instantly share code, notes, and snippets.

@juanique
Created August 22, 2012 16:07
Show Gist options
  • Select an option

  • Save juanique/3427063 to your computer and use it in GitHub Desktop.

Select an option

Save juanique/3427063 to your computer and use it in GitHub Desktop.
A simple django template filter to strip accents to a string (based on http://stackoverflow.com/questions/517923/what-is-the-best-way-to-remove-accents-in-a-python-unicode-string )
from django import template
import unicodedata
register = template.Library()
def stripaccents(value, arg=""):
if type(value) == str:
return value
return ''.join((c for c in unicodedata.normalize('NFD', value) if unicodedata.category(c) != 'Mn'))
register.filter("stripaccents", stripaccents)
@jpmcpe
Copy link

jpmcpe commented Oct 8, 2017

for what is the seven line? why do you return when is str?

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