1 2 3 4 5 6 7 8 9 10 | from django import template
import re
register = template.Library()
@register.filter
def slugify(string):
string = re.sub('\s+', '_', string)
string = re.sub('[^\w.-]', '', string)
return string.strip('_.- ').lower()
|
More like this
- slugify js -> python by santuri 4 years, 11 months ago
- slug_and_slash_to_dash - modified slugify for urls by bradmontgomery 1 year, 5 months ago
- Automate unique slugs by taojian 4 years, 1 month ago
- Using the built-in slugify filter outside a template by jcroft 4 years, 11 months ago
- Built-in Slugify with filtering. by jcrawford 2 years, 10 months ago
Comments
From what I hear dashes are supposed to be more search engine friendly. According the a Search Engine guy I know, the search engines equate a underscore to be an non-char. So school_closes_due_to_health_issues turns into schoolclosesduetohealthissues.
I take that stuff with a grain of salt though... I think the folks at Google are smart enough to realize folks use underscores as spaces in slugs.
Donno.
#