23201 向html中传递参数
路由:
(r'/',index.IndexHandler)
代码:
from tornado.web import RequestHandler
class IndexHandler(RequestHandler):
def get(self):
sz=100
pr={
"age":18,
"name":"wu"
}
self.render('home.html',nu=sz,zd=pr)
html:
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>home</title> 6 </head> 7 <body> 8 <h1>home界面</h1> 9 <!--参数可以是 {{参数名}}表示 --> 10 <!--也可以是 {{表达式}} --> 11 <!--注意,html里面不能改变参数原始值--> 12 <!--传递字典时,使用 字典.["键名"] 取值--> 13 <h2>nu为{{nu}}</h2> 14 <h3>nu+1为{{nu+1}}</h3> 15 <h4>字典中年龄为{{zd['age']}}</h4> 16 </body> 17 </html>
===今日我言===========
勇气 让人进步
===================
浙公网安备 33010602011771号