Answer the question
In order to leave comments, you need to log in
How to properly optimize urls in Django?
Tell me the right way to optimize the url in a Django project. Now I am getting a specific article at the link localhost/articles/get/1 I would like to do localhost/krem-dlya-britya
Answer the question
In order to leave comments, you need to log in
1. Add a field to the model, something like this
2. Then specify the slug in the urls, like this
3. Well, already in the view
def article_detail(request, slug):
article = get_object_or_404(Article, slug=slug)
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question