1 2 3 4 5 6 7 8 9 10 11 12 | from django.template.defaultfilters import slugify
removelist = ["a", "an", "as", "at", "before", "but", "by", "for",\
"from","is", "in", "into", "like", "of", "off", "on",\
"onto","per","since", "than", "the", "this", "that",\
"to", "up", "via","with"]
new_topic = "this is a test with a long string which has many words up to here."
clean_list = [str(word) for word in new_topic.split() if word not in removelist]
new_slug = slugify(clean_list)
|
More like this
- Using the built-in slugify filter outside a template by jcroft 6 years, 2 months ago
- Slugify alternative by exogen 6 years, 1 month ago
- AutoSlugField and unique_slugify combined by Ciantic 3 years, 4 months ago
- Filter to add zero-width space to break up long words by jayliew 8 months ago
- Automatically slugify slug fields in your models by Aliquip 6 years, 2 months ago
Comments
List comprehensions have been in Python a lot longer than 2.5; since 2.0, I believe. Even generator expressions were introduced already in 2.4.
#
Arg, you're right - I was thinking ternary operators, for some reason... wups.
#