P
P
Pyramidec2017-07-28 22:26:51
Django
Pyramidec, 2017-07-28 22:26:51

How to throw a 404 error if a non-existent link passed regex in urls.py?

Good evening!
Dealt with non-existent pages. But what about categories? You can edit the link in the field and voila - the regular expression check passes, but does not exist in the database. And how to filter?
I wanted to make a filter by the parent slug link that is in the model, but apparently you can only filter by your own fields.
At the moment such a view.

def articles_list(request, category_slug):
    articles = get_list_or_404(Article.objects.order_by('name'))
    context = {
        'articles': articles
    }
    return render(request, 'my_app/articles_list.html', context)

The model has a parent field that refers to the category. But the category_slug does not pass the name of the parent, but its link.
Help me please. I did not find anything in the documentation for such cases.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question