Skip to content


Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Custom-slugify() support for django.

Python Package Build Status Docs Code Coverage License

What are slugs?

Slugs are URL's, typically generated from post titles, that you want to be both human readable and a valid URL. They are SEO friendly.

Django provides a slugify function in django.utils.text.slugify which is also made available as a default filter.

Django slugs can be automatically generated in django models via packages such as:

The problem

This project is based on an article from covering django's import strings.

Corner cases exist with slugification. For instance:

Term django.utils.text.slugify What you want
C c (correct) n/a
C++ c cpp
C# c c-sharp

To make matters worse, if using a specialized model field like AutoSlugField from django-autoslug or django-extensions, the default behavior may be to name the slugs for C++ and C# to "c-1", "c-2" after "c" is taken.

Here's another case, acronyms / shorthands:

Term django.utils.text.slugify What you (may) want
New York City new-york-city nyc
Y Combinator y-combinator yc
Portland portland pdx
Texas texas tx
$ '' (empty) usd, aud, etc?
US$ us usd
A$ a aud
bitcoin bitcoin btc
United States united-states usa
League of Legends league-of-legends league
Apple® iPod Touch apple-ipod-touch ipod-touch

Each website and niche has its own edge cases for slugs. So we need a solution that can scale, where you can craft your own functions.

How django-slugify-processor helps

This builds on top of django.utils.text.slugify to handle your django project's edgecases. By default, django-slugify-processor will be a pass through to django's default behavior. Adding slugification functions via your Django project's settings file allows you to adjust.


$ pip install django-slugify-processor


To create a processor, create a function that accepts a string, and returns a string. Assume this is project/app/

def my_processor(value):
   value = value.replace('++', 'pp')
   return value

Inside of your settings, add a SLUGIFY_PROCESSORS list of strings that points to the function. Anything that's compatible with import_string, in your settings file:



In normal django code

Import slugify from django_slugify_processor.text:

from django_slugify_processor.text import slugify

> 'cpp'

Template code

django-slugify-processor is designed to override the built-inslugify filter.

via load

You can load by default via {% load django_slugify_processor %} in your template.

In your settings INSTALLED_APPS:


In your template:

{% load slugify_processor %}

via built-in

To make this available in all templates, in the OPTIONS of your template engine, add django_slugify_processor.template_tags:

    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'OPTIONS': {
        'builtins': [

From within the template file:


Output should be: cpp


For the most up to date documentation, view the documetation for the plugin you're using (e.g. django-autoslug or django-extensions).

To use django-slugify-processor's slugify instead of django's default, there will be a field option to use the function.


Tested with 1.9.7 (2017-11-26):

from django.db import models

from django_extensions.db.fields import AutoSlugField
from django_slugify_processors.text import slugify

class MyModel(models.Model):
    title = models.CharField(max_length=255)
    slug = AutoSlugField(


Tested with 1.9.3 (2017-11-26):

from django.db import models

from autoslug import AutoSlugField
from django_slugify_processors.text import slugify

class MyModel(models.Model):
    title = models.CharField(max_length=255)
    slug = AutoSlugField(


  • tox.ini based off DRF's (BSD 2-clause licensed)
  • yapf configuration based off RTD /'s (MIT-licensed)

Project details


Install stable:

$ pip install django-slugify-processor

Local installation:

$ git clone
$ cd ./django-slugify-processor
$ poetry shell
$ pipenv install


$ make test