Answer the question
In order to leave comments, you need to log in
How to change the slug to the desired view?
You need to save the slug in this form
site.com/123-blablabla
. I do this in the Model
class Article(models.Model):
title = models.CharField(max_length=120, null=False)
slug = models.SlugField(null=False, blank=True, unique=True)
def save(self, *args, **kwargs):
self.slug = slugify(f"{str(self.id)}-{self.title}", lowercase=True)
super().save(*args, **kwargs)
path('articles/<slug:slug>/', DetailArticleView.as_view(), name='article_detail'),
site.com/none-blablabla
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question