---
title: '|slugify'
description: converts a string to a slug.
date: '2026-08-02'
categories:
  - Filter
  - URL
canonical: https://coolify.djangotemplatetagsandfilters.com/filters/slugify/
doc_link: https://docs.djangoproject.com/en/6.0/ref/templates/builtins/#slugify
---

# |slugify

converts a string to a slug.

## Documentation

Converts a string to a slug, for use in a URL. Specifically, it:

1. Converts to lowercase ASCII.
2. Converts spaces to hyphens.
3. Removes all characters except letters, numbers, underscores, and hyphens.
4. Strips leading and trailing whitespace.

### Variable

```django
blurb_text = 'Aren’t you a smart one?'
```

### Template

```django
{{ blurb_text|slugify }}
```

### Result

```django
arent-you-a-smart-one
```

## Commentary

The `slugify` filter can be used to coerce an integer in to a string in a template. Consider the following use case:

```django
<select name="order">
  {% for field in order_fields %}
    <option value="{{ forloop.counter0 }}"
      {% if request.GET.order == forloop.counter0|slugify %}selected{% endif %}
    >{{ field }}</option>
  {% endfor %}
</select>
```

Because `order` is passed on the querystring, it will be a string, but `forloop.counter0` will be an integer, so the two will never be equal. Coercing `forloop.counter0` to a string using `slugify` solves the problem.

An alternative would be to coerce `request.GET.order` in to an integer using the [`add` filter as shown here](/filters/add/).
