[英]Am i missing something on templates on django
This is my code on html file on a django project.这是我在 django 项目的 html 文件上的代码。 I am using this code on this function
我在这个 function 上使用这个代码
def home(request):
context = {
'post': posts
}
return render(request,'blog/home.html',context
It does not display anything when I see page source it's just bacis html code head and body empty当我看到页面源时它不显示任何内容它只是 bacis html 代码头和身体空
<html>
<head>
<title> </title>
</head>
<body>
{% for post in posts %}
<h1>{{post.title}}</h1>
<p>By {{post.author}} on {{post.date_posted}}</p>
<p>{{post.content}}</p>
{% endfor %}
</body>
</html>```
It is a typo.这是一个错字。 You need to change the context in your view from:
您需要从以下位置更改视图中的上下文:
context = { 'post': posts }
to至
context = { 'posts': posts }
^^^^^^^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.