• 继续django创建项目案例1续02的后续 继续项目:

修改index.html代码如下:

<!DOCTYPE html><html lang="en"><head>    <  charset="UTF-8">    < > </ ></head><body><ul>{%for book in list%}<li>{{book.b }}</li>{%endfor%}</ul></body></html>

image.png

修改views.py文件代码如下:

#coding:utf-8from django.shortcuts import renderfrom 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. s.all()    context={'list':bookList}    return render(request,'booktest/index.html',context)

image.png

效果图:
image.png

收藏 打印