首页 > 解决方案 > 上下文不呈现我的 html 页面 - django

问题描述

所以观点是:

def username(request):
context = {}
if request.POST:
    pass
else:
    context['title'] = 'type a username'
    return render(request, 'update/one-input.html', context)

然后在html页面中:

<h5>{{ title }}</h5>

当我运行该页面时,它没有给我任何错误,并且它没有在标题内显示任何想法我在页面的另一个视图中执行相同的代码及其工作,为什么在这个视图中不起作用,那么问题是什么?):

标签: pythondjango

解决方案


我认为您需要将最后一行更改为:

return render(request, 'update/one-input.html', {'context': context})

然后在你的html你将拥有context它的所有内容。


推荐阅读