我的索引页为空,我得到白页



我正在学习 Django,我做了所有事情,但当我得到空的白页时。 使用源代码,我只得到标签。 我把我的 views.py 和索引放了.html我在使用Virtualenv的终端中甚至没有收到错误。当我尝试进入网站时,我没有收到错误 9月 24, 2019 - 18:09:51 Django 版本 2.2.5,使用设置 'Web.settings' 在 http://127.0.0.1:8000/启动开发服务器 使用 CONTROL-C 退出服务器。

指数

<!DOCTYPE html>
<html>
<head>
{% for title in titles %}
<title>{{ titles.title }}</title>
{% endfor %}
</head>
<body>
{% for post in posts %}
<h1>{{ post.title }}</h1>
<p> By {{ post.author}} on {{ post.date_posted }}</p>
<p> {{ post.concent}} </p>
{% endfor %}
</body>
</html>

视图

from django.shortcuts import render
from django.http import HttpResponse
titles = [
{'title':'My Own CMS'}
],
posts =[
{   
'author': 'CoreyMS',
'title':'Blog Post 1',
'content': 'First Post',
'date_posted': 'August 26,2019'       
},
{
'author': 'George',
'title':'Blog Post 2',
'content': 'seccond Post',
'date_posted': 'August 29,2019'       
},
]
def home(request):
headset = {
'title': titles
},
context = {
'posts': posts
}
return render(request, 'blog/index.html')
def about(request):
return render(request,'blog/shesaxeb.html')

您定义了上下文字典,但没有将其添加到返回中。


context = {
'posts': posts,
}

def about(request):
return render(request,'blog/shesaxeb.html', context)

最新更新