API Reference¶
Processor Pipeline¶
SLUGIFY_PROCESSORS is a Django setting containing dotted import strings. Each
string must resolve through django.utils.module_loading.import_string() to
a callable that accepts a str and returns a str.
Processors run in list order for every slugify()
call. Each processor receives the previous processor’s output, then the final
value passes to django.utils.text.slugify() with the caller’s
allow_unicode value.
Keep processors pure and inexpensive. A processor should not depend on request state, database writes, or network calls because slugification can run inside model-field saves, template rendering, and bulk import jobs.
Slugify function¶
-
django_slugify_processor.text.slugify(value, allow_unicode=False)¶django_slugify_processor.text.slugify(value, allow_unicode=False)¶
Override Django’s default slugify behavior with custom processors.
Run
valuethrough functions declared inSLUGIFY_PROCESSORS. The value then passes to Django’sdjango.utils.text.slugify().Examples
With no processors configured, this matches Django’s slugifier:
>>> from django_slugify_processor.text import slugify >>> slugify("c++") 'c'
Processors run before Django’s final slugification:
>>> from django.test import override_settings >>> with override_settings( ... SLUGIFY_PROCESSORS=["test_app.coding.slugify_programming"], ... ): ... slugify("c++") 'cpp'
The
allow_unicodeflag is passed to Django after processors run:>>> with override_settings( ... SLUGIFY_PROCESSORS=["test_app.coding.slugify_programming"], ... ): ... slugify("東京 c++", allow_unicode=True) '東京-cpp'
Template filter¶
The template filter delegates to slugify()
with its default allow_unicode=False behavior. Load it explicitly with
{% load slugify_processor %}, or install
django_slugify_processor.templatetags.slugify_processor as a template builtin
when the whole template engine should shadow Django’s built-in slugify filter.
-
django_slugify_processor.templatetags.slugify_processor.slugify(value)¶django_slugify_processor.templatetags.slugify_processor.slugify(value)¶
Template filter override for Django’s
django.utils.text.slugify().Install via a template builtin, or load with
{% load slugify_processor %}.Examples
>>> from django.template import Context, Template >>> from django.test import override_settings >>> with override_settings( ... INSTALLED_APPS=[ ... "django.contrib.contenttypes", ... "django.contrib.auth", ... "test_app", ... "django_slugify_processor", ... ], ... TEMPLATES=[ ... { ... "BACKEND": "django.template.backends.django.DjangoTemplates", ... "APP_DIRS": True, ... }, ... ], ... SLUGIFY_PROCESSORS=["test_app.coding.slugify_programming_languages"], ... ): ... Template( ... '{% load slugify_processor %}{{ "C++ Guide"|slugify }}', ... ).render(Context({})) 'cpp-guide'
Package metadata¶
-
django_slugify_processor.__version__ = '1.11.0'¶django_slugify_processor.__version__ = '1.11.0'¶
str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to ‘utf-8’. errors defaults to ‘strict’.