N
N
Nikita Mokhovikov2021-09-05 00:06:57
Django
Nikita Mokhovikov, 2021-09-05 00:06:57

How to automatically generate an article URL?

It is necessary to implement URL generation for the written article. That is, when creating any article ( so far only in the admin panel ), it is necessary that after pressing the Save button , the URL for this article would be automatically generated.

There is a piece of code for generation. I did the same operation, but on Flask and it worked:

def slugify(s):
    pattern = r'[^\w+]'
    return re.sub(pattern, '-', s)

How to do the same but in Django?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antonio Solo, 2021-09-05
@solotony

option 1
slug = models.SlugField()
option 2
pip install transliterate
...
from transliterate import slugify

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question