【发布时间】:2020-01-24 21:54:56
【问题描述】:
我正在学习 Django,我什么都做了,但是当我得到空白页时。并且使用源代码我只得到标签。我把我的views.py和index.html放在我使用virtualenv的终端中我什至没有得到错误。当我尝试进入网站时,我没有收到错误 2019 年 9 月 24 日 - 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')
【问题讨论】:
标签: python-3.x django-templates