step1 : booktest/views.py
from django.shortcuts import render
from django.http import *
# from django.template import RequestContext,loader
from .models import *
# 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/index1.html',context)
def show(request,id):
book = BookInfo.objects.get(pk=id)
heroList = book.heroinfo_set.all()
context = {'list':heroList}
return render(request,'booktest/show.html',context)
step2: templates/booktest/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Title</title>
</head>
<body>
<ul>
{%for book in list%}
<li><a href="{{book.id}}">{{book.btitle}}</a></li>
{%endfor%}
</ul>
</body>
</html>
step3:templates/booktest/show.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Title</title>
</head>
<body>
<ul>
{%for hero in list%}
<li>{{hero.hname}}</li>
{%endfor%}
</ul>
</body>
</html>