标签:
修改blog/templates/index.html
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>{{title}}</title> </head> <body> <h1>hello {{user}}</h1> </body> </html>
修改blog/views.py
from django.shortcuts import render_to_response def index(req): return render_to_response(‘index.html‘,{‘title‘:‘my page‘, ‘user‘:‘alu02‘})
测试界面
修改blog/views.py
from django.shortcuts import render_to_response def index(req): user = {‘name‘:‘alu02‘,‘age‘:1,‘sex‘:‘male‘} return render_to_response(‘index.html‘,{‘title‘:‘my page‘, ‘user‘:user})
修改blog/templates/index.html
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>{{title}}</title> </head> <body> <h1>I am {{user.name}}</h1> <h1>I am {{user.age}} years old</h1> <h1>I am {{user.sex}}</h1> </body> </html>
界面测试
同理,我们可以传递类的实例,从而使用属性和方法
标签:
原文地址:http://www.cnblogs.com/onmyway227/p/5252205.html