Log in

Use unidecode to support slugify when containing characters other than letters and digits

  • 25 Jan '15
def slugify(text, delim=u'-'):
    text = unidecode.unidecode(text)
    result = []
    for word in _punct_re.split(text.lower()):
        if word:
            result.append(word)
    return text_type(delim.join(result))

From flask snippet

nitelyEsteban Castro Borsani
  • 1
  • 25 Jan '15

It's slightly more complicated than that... I'd rather wait for Django 1.8 to support it out of the box.

See:
https://groups.google.com/forum/#!topic/django-developers/Ic2hH3AWdUg/discussion
https://code.djangoproject.com/ticket/16501
https://github.com/django/django/pull/3729

On a second thought, I'm not using forms.SlugField or the django's admin, so it might be all right.

nitelyEsteban Castro Borsani
  • 29 Mar '15

I added support for this by including an extra dependency.

Reply