MCPcopy
hub / github.com/django/django / slugify

Function slugify

django/utils/text.py:466–483  ·  view source on GitHub ↗

Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated dashes to single dashes. Remove characters that aren't alphanumerics, underscores, or hyphens. Convert to lowercase. Also strip leading and trailing whitespace, dashes, and underscores.

(value, allow_unicode=False)

Source from the content-addressed store, hash-verified

464
465@keep_lazy_text
466def slugify(value, allow_unicode=False):
467 """
468 Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated
469 dashes to single dashes. Remove characters that aren't alphanumerics,
470 underscores, or hyphens. Convert to lowercase. Also strip leading and
471 trailing whitespace, dashes, and underscores.
472 """
473 value = str(value)
474 if allow_unicode:
475 value = unicodedata.normalize("NFKC", value)
476 else:
477 value = (
478 unicodedata.normalize("NFKD", value)
479 .encode("ascii", "ignore")
480 .decode("ascii")
481 )
482 value = re.sub(r"[^\w\s-]", "", value.lower())
483 return re.sub(r"[-\s]+", "-", value).strip("-_")
484
485
486def camel_case_to_spaces(value):

Callers

nothing calls this directly

Calls 3

normalizeMethod · 0.45
decodeMethod · 0.45
encodeMethod · 0.45

Tested by

no test coverage detected