首页 > 解决方案 > 切换页面后计数视图在导航栏上不起作用

问题描述

我有一个带有导航栏的页面,其中帖子的计数工作得很好,但是在我转到其他页面后,可以说联系人计数显示为(). 我该如何解决这个问题?

on index.html the result is : total posts (43434)
on contacts.html the result is : total posts ()

索引.html

<div> total posts ({{ postcounts }}) </div>

视图.py

def index(request):
    posts = Post.objects.filter(active=True)
    pcounts = posts.count()
    context = {
        'postcounts':pcounts,
        }
    
    return render(request, 'posts/index.html', context)

标签: djangodjango-modelsdjango-formsdjango-viewsdjango-templates

解决方案


推荐阅读