Py学习  »  Django

Django:在不同应用程序中的html文件之间传递上下文数据

Diana Mele • 3 年前 • 1605 次点击  

如何将我在一个视图中创建的上下文数据(inthis case profile_total变量)传递到另一个应用程序的html模板? 这是我的代码:

附件一。意见。py

def view_profile(request):
    profile_total = UserProfile.objects.all().count()
    return render(request, 'profile/user_profile.html', {'profile_total': profile_total})   

附件2。统计数据。html

<div class="container">
<h1> Show </h1>
Profile submitted: {{ profile_total }}
</div>

现在只显示了一个空白区域,而不是提交的个人资料的计数。谢谢大家的帮助!

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/133855
文章 [ 1 ]  |  最新文章 3 年前