【发布时间】:2018-08-30 04:20:52
【问题描述】:
我正在尝试将数据从我的 views.py 获取到 html 页面。 如果views.py代码是这样的
def VerifiedBySuperuser(request):
if request.method == 'POST':
vbs = MaanyaIT_EXAM48_ManageQuestionBank()
vbs.QuestionID = MaanyaIT_EXAM48_ManageQuestionBank.objects.get(QuestionID=request.POST.get(QuestionID, None))
vbs.QuestionInEnglishLang = request.POST.get('QuestionInEnglishLang', None)
vbs.save()
else:
return render(request, 'exam48app/verifiedbysuperuser.html')
那么 html 页面的代码应该如何查看我的所有数据到 tamplates..
这是我的html页面
<form class="from-horizontal" method="post" enctype="multipart/form-data">
{% csrf_token %}
<div class="post-entry">
{{ MaanyaIT_EXAM48_ManageQuestionBank.QuestionInEnglishLang }}
</div>
</form>
现在我该怎么办?
【问题讨论】:
-
return render(request, 'exam48app/verifiedbysuperuser.html', context={"data":yourdata}) -
不不,我想知道我应该在html页面中写什么,以便数据显示在html页面中。
-
您需要在渲染函数中返回一个上下文变量。这个上下文变量(你的数据)可以在你的 html 中用作 {{variable_name}} ,无论你想使用它。
-
查看html页面...
标签: html django django-2.0