slug_and_slash_to_dash - modified slugify for urls

 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

  1. Smart append slash middleware by akaihola 6 years, 2 months ago
  2. Automatically slugify slug fields in your models by Aliquip 7 years, 1 month ago
  3. Slugify alternative by exogen 7 years ago
  4. Ensure submitted slugs do not conflict with existing resolvable URLs by ElfSternberg 4 years, 10 months ago
  5. Using the built-in slugify filter outside a template by jcroft 7 years, 1 month ago

Comments

(Forgotten your password?)