Chinaunix首页 | 论坛 | 博客
  • 博客访问: 570533
  • 博文数量: 80
  • 博客积分: 2393
  • 博客等级: 大尉
  • 技术积分: 1434
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-03 21:46
个人简介

己所不欲勿施于人!

文章分类

全部博文(80)

文章存档

2017年(1)

2016年(9)

2014年(1)

2013年(17)

2012年(5)

2011年(13)

2010年(9)

2009年(8)

2008年(17)

分类: Python/Ruby

2013-04-27 13:36:59

render_to_response的第一个参数为模板名称,比如/home/yang/mysite/templates下的文件mytemp.html,第二个参数为字典。例如:

render_to_response('mytemp.html', {'current_date':now})

在实验中,如果想在第二个参数中放置两个字典,比如

render_to_response('mytemp.html', {'current_date':now}, {'hour':hour_now})

此时,第二个参数将会被忽略,在生成的网页文件中,只会出现第一个参数,要解决这个问题,可以采用字典变量。例如

dic = {'current_date':now, 'hour':hour_now}

render_to_response('mytemp.html', dic)

到此,问题解决,两个变量均能在页面中显示。

在页面获取dic变量的值可以通过使用两个{{}}来获取。

阅读(4233) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~