[root@localhost myblog_rocky]# vihomepage/views.py
代码如下
from django.shortcuts importrender_to_response
user =("name":"rocky","age":"22","constellation
user =("name":"rocky","age":"22","constellation":"Taurus
#from django.http import HttpResponse
from django.shortcuts importrender_to_response
user =("name":"rocky","age":"22","constellation":"Taurus","QQ":"920862715")
def index(req):
# return HttpResponse(‘<h1>hello welcome to Rocky\‘sblog!</h1>‘)
return render_to_response(‘index.html‘,{"title":"hellowelcome to Rocky\‘s blog!","user":user})vi homepage/templates/index.html
代码如下:
<li>constellation:{{user.constellation}}</li>
<HTML>
<HEAD>
<META NAME="GENERATOR"Content="Microsoft Developer Studio">
<META HTTP-EQUIV="Content-Type"content="text/html; charset=gb_2312-80">
<TITLE>Rocky‘s blog</TITLE>
</HEAD>
<BODY>
<h1>{{title}}</h1>
<li>name: {{user.name}}</li>
<li>age: {{user.age}}</li>
<li>constellation:{{user.constellation}}</li>
<li>QQ: {{user.QQ}}</li>
</BODY>
</HTML>python manage.py runserver
本文出自 “Rocky___” 博客,请务必保留此出处http://zutianbiao.blog.51cto.com/1361296/1363883
django基础4--django模板变量的使用,布布扣,bubuko.com
原文:http://zutianbiao.blog.51cto.com/1361296/1363883