JavaCake JavaCake - 7 months ago 29
Python Question

How to slugify while still maintaining UTF-8 letters

I am trying to slugify UTF-8 text, which in this case involves characters such as æøå, which I want to maintain.

When I use slugify it does not maintain the UTF-8 chars:

>>> from slugify import slugify
>>> slugify(u'æsel (øen)')

It should be


Use a different library to slugify; the unicode-slugify library output fits your requirements exactly:

$ bin/pip install unicode-slugify
Downloading/unpacking unicode-slugify
  Downloading unicode-slugify-0.1.1.tar.gz
  Running (path:/.../build/unicode-slugify/ egg_info for package unicode-slugify

Downloading/unpacking django (from unicode-slugify)
  Downloading Django-1.7-py2.py3-none-any.whl (7.4MB): 7.4MB downloaded
Installing collected packages: unicode-slugify, django
  Running install for unicode-slugify

Successfully installed unicode-slugify django
Cleaning up...
$ bin/python
Python 2.7.8 (default, Sep 19 2014, 22:15:41) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.51)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from slugify import slugify
>>> slugify(u'æsel (øen)')
>>> print slugify(u'æsel (øen)')