slugify python
# shell/bash
pip install python-slugify
# or
pip3 install python-slugify
# python
from slugify import slugify
slugify python
# shell/bash
pip install python-slugify
# or
pip3 install python-slugify
# python
from slugify import slugify
slugify django
from django.template.defaultfilters import slugify
# in the view maybe while saving the form...
def savedata()
form = someform(request.POST or None)
if form.is_valid():
new_post = form.save(commit=False) #for holding it before actually saving
# slugify returns elephant-is-big if passed slugify("elephant is big")
# and therefore a hyphened slug
new_post.slug = slugify(form.title)
new_post.save()
# model may look like this
class SomeModel(models.Model):
title = models.Charfield()
slug = models.SlugField(unique=True)
## other fields
slug urls django
path('<slug:slug>,<int:id>/', views.article_detail, name='article'),
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us