Created
February 1, 2016 15:19
-
-
Save atelic/b11b3f5086027ae08870 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import unicodedata | |
def slugify(value): | |
""" | |
Convert spaces to hyphens., remove characters that aren't alphanumerics, underscores, or hyphens. | |
Convert to lowercase. Also strip leading and trailing whitespace. | |
From Django's filter: https://github.com/django/django/blob/60586dd7379b295b72d8af4e03423c286913b5e8/django/utils/text.py#L415 | |
""" | |
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii') | |
value = re.sub('[^\w\s-]', '', value).strip().lower() | |
return re.sub('[-\s]+', '-', value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment