我的索引页为空,我正在白页上

问题描述 投票:0回答:1

我正在学习Django,但我做了所有事情,但是当我得到空白页时。和源代码,我只获得标签。我把我的views.py和index.html放在终端上什至没有错误,我正在使用virtualenv。当我尝试进入网站时,我没有收到错误消息九月24,2019-18:09:51Django版本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')
python-3.x django-templates
1个回答
0
投票

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


context = {
    'posts': posts,
}


def about(request):
    return render(request,'blog/shesaxeb.html', context)
© www.soinside.com 2019 - 2024. All rights reserved.