<HTML> <Head> <title>DOcument</title> </Head> <Body> <H1>{{User}}</H1> </BR><li>{{user.0}}</li>//Note: The specifics of how the list data is received <li>{{user.1}}</li> < Li>{{user.2}}</li> </BR> <Li>Method:{{user.say}}</Li> <!--Note that there are no brackets behind it. - </Body></HTML>
2. Modify the views.py file
#-*-coding:cp936-*- fromDjango.httpImportHttpResponse#import templates related packages; loader: loader, loading HTML templates fromDjango.templateImportLoader,context#Learn to define the first class in a views.pyclassPerson ():def __init__(self,name,age,sex): Self.name=name Self.age=Age Self.sex=Sex#Defining Methods defSay (self):return 'My name is'+Self.name#Define an index viewdefIndex (Request): T=loader.get_template ('index.html') #passing data to an HTML page #instantiation of #Person=person (' Fengmei ', +, ' female ')booklist=[' python ', ' C + + ', ' java ', ' php ' #接收list数据C=context ({'User': Booklist}) #Rendering Methodst=T.render (c)returnHttpResponse (t)
Django Definition Template Variable 04 (receive list data)