Using the built-in slugify filter outside a template

1
2
3
4
5
6
7
8
if city:
    from django.template import defaultfilters
    city_slug = defaultfilters.slugify(city)
    state_slug = defaultfilters.slugify(state_abbr)
    if state_slug:
        location_slug = city_slug + '-' + state_slug
    else:
        location_slug = city_slug

More like this

  1. Built-in Slugify with filtering. by jcrawford 5 years ago
  2. slugify js -> python by santuri 7 years, 1 month ago
  3. Automatically slugify slug fields in your models by Aliquip 7 years, 1 month ago
  4. Database template loader by doomatel 2 years ago
  5. slug_and_slash_to_dash - modified slugify for urls by bradmontgomery 3 years, 7 months ago

Comments

obeattie (on February 28, 2007):

Yeah, I do this all the time too when importing stuff from APIs

#

canen (on February 28, 2007):

People just need to realize that filters are just functions. I usually use the striptags filter when sending emails.

#

(Forgotten your password?)