django - 切换页面后计数视图在导航栏上不起作用
问题描述
我有一个带有导航栏的页面,其中帖子的计数工作得很好,但是在我转到其他页面后,可以说联系人计数显示为()
. 我该如何解决这个问题?
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)
解决方案
推荐阅读
- c# - 使用 Windows 服务启动应用程序或批处理文件
- sql-server - SMO 仅对数据库及其设置编写脚本(而不是其中的对象)
- python - 如何根据逻辑创建布尔系列:(0 后接 1 为真。1 前接 0 为真。其他均为假)
- swift - 如何在 SwiftUI WKWebView 中实现 WKUIDelegate?
- wordpress - 获取存储在 DB 中的转发器子字段的所有值
- ruby-on-rails - Rails 中的多个默认 URL 值?
- azure - “字符串”类型的表达式与 ADFv2 中 If 条件上的字段“表达式”不匹配
- flutter - 当我使用具有自动对焦的文本字段时,Flutter 会引发错误
- php - PHP 'For Each' 将行从数组或字符串插入 mysql
- android - 如何将“com.unity3d.player.UnityPlayer”导入我的 Android 库?