【发布时间】:2021-10-19 19:23:10
【问题描述】:
如何将在我的一个视图中创建的上下文数据(在他的案例 profile_total 变量中)传递给另一个应用程序的 html 模板? 这是我的代码:
app1.views.py
def view_profile(request):
profile_total = UserProfile.objects.all().count()
return render(request, 'profile/user_profile.html', {'profile_total': profile_total})
app2.stats.html
<div class="container">
<h1> Show </h1>
Profile submitted: {{ profile_total }}
</div>
现在它只显示一个空格,而不是提交的配置文件的数量。谢谢大家的帮助!
【问题讨论】:
-
你的html不是
profile/user_profile.html? (因为你提到了app2.stats.html)。 -
您确定 (a) 您渲染了正确的模板,并且 (b) 您触发了正确的视图吗?