[Python] django get_object() getting called many times

Discussão em 'Python' iniciado por Stack, Junho 7, 2025.

  1. Stack

    Stack Membro Participativo

    I have a model- Article, and this code snippet

    class ArticleDetailView(HitCountDetailView):
    model = Article
    # some code...

    def get_object(self):
    article = super(ArticleDetailView, self).get_object()
    slug = self.kwargs['slug']
    article = get_object_or_404(Article, slug=slug)

    print(article.some_count.counts)

    return article


    this code is line printing the value of article.some_count_counts 3 times, it means the function get_object() is getting called 3 times.

    But why so? that's my question.

    Continue reading...

Compartilhe esta Página