📅  最后修改于: 2023-12-03 14:47:29.300000             🧑  作者: Mango
Slug is a package in Python that is used to create slugs from strings. A slug is a URL-friendly version of a string that typically includes only lowercase letters and hyphens.
You can install Slug with pip:
pip install slug
Import the slugify
function from the slug
package:
from slug import slugify
You can use this function to create a slug from a string:
text = "This is a string to be slugified"
slug = slugify(text)
print(slug)
This will output:
this-is-a-string-to-be-slugified
Slug offers several features, including:
You can use these features by passing arguments to the slugify
function:
text = "<h1>This is a string to be slugified with non-ASCII characters: åäö</h1>"
slug = slugify(text, allow_unicode=True, separator="_")
print(slug)
This will output:
this_is_a_string_to_be_slugified_with_non_ASCII_characters_åäö
In conclusion, Slug is a powerful tool for creating slugs from strings in Python. Its simple syntax and extensive feature set make it a great choice for developers looking to create URL-friendly strings.