String slugification in Python

前端 未结 10 1092
粉色の甜心
粉色の甜心 2020-11-30 23:10

I am in search of the best way to \"slugify\" string what \"slug\" is, and my current solution is based on this recipe

I have changed it a little bit to:

<         


        
10条回答
  •  无人及你
    2020-11-30 23:40

    A couple of options on GitHub:

    1. https://github.com/dimka665/awesome-slugify
    2. https://github.com/un33k/python-slugify
    3. https://github.com/mozilla/unicode-slugify

    Each supports slightly different parameters for its API, so you'll need to look through to figure out what you prefer.

    In particular, pay attention to the different options they provide for dealing with non-ASCII characters. Pydanny wrote a very helpful blog post illustrating some of the unicode handling differences in these slugify'ing libraries: http://www.pydanny.com/awesome-slugify-human-readable-url-slugs-from-any-string.html This blog post is slightly outdated because Mozilla's unicode-slugify is no longer Django-specific.

    Also note that currently awesome-slugify is GPLv3, though there's an open issue where the author says they'd prefer to release as MIT/BSD, just not sure of the legality: https://github.com/dimka665/awesome-slugify/issues/24

提交回复
热议问题