- Author:
- bradmontgomery
- Posted:
- August 28, 2010
- Language:
- Python
- Version:
- 1.2
- Score:
- 0 (after 0 ratings)
This filter converts slashes to spaces in a a sting and then slugify's the result. However, it ignores leading and trailing slashes. For example, it can take something like this:
/some/url/with-an-existing-slug/
And turn it into this:
some-url-with-an-existing-slug
The filter was originally written to use the curent url as the disqus_identifier for Disqus comments. For example:
{{ request.META.PATH_INFO|slug_and_slash_to_dash }}
1 2 3 4 5 6 7 8 9 10 11 12 13 | from django.template import Library
from django.template.defaultfilters import slugify, stringfilter
register = Library()
@register.filter
@stringfilter
def slug_and_slash_to_dash(value):
"""
Converts any slashes in the given value into spaces, then slugify's the result.
Leading and Trailing slashes (e.g. /some/url/) are ignored.
"""
return slugify(' '.join(value.split('/')))
|
More like this
- find even number by Rajeev529 2 weeks, 1 day ago
- Form field with fixed value by roam 1 month ago
- New Snippet! by Antoliny0919 1 month, 2 weeks ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 4 months ago
- get_object_or_none by azwdevops 7 months, 3 weeks ago
Comments
Please login first before commenting.