- 继续django创建项目案例1续02的后续 继续项目:
修改index.html代码如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<ul>
{%for book in list%}
<li>{{book.btitle}}</li>
{%endfor%}
</ul>
</body>
</html>
修改views.py文件代码如下:
#coding:utf-8
from django.shortcuts import render
from django.http import *
from .models import *
# from django.template import RequestContext,loader
# Create your views here.
def index(request):
# temp = loader.get_template('booktest/index.html')
# return HttpResponse(temp.render())
bookList=BookInfo.objects.all()
context={'list':bookList}
return render(request,'booktest/index.html',context)
效果图: