畅想!!

馨园

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

传递多个参数时使用context={}字典形式

info.py

 1 from datetime import datetime
 2 
 3 @app.route('/info/')
 4 def person():
 5     class MyPerson(object):
 6         Email = 'jpal124@gmail.com'
 7         Time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
 8     dell=MyPerson()
 9     context={'username':'Jack','age':39,'pdell':dell}
10     return  render_template('info.html',**context)
View Code

info.html

 1 <!doctype html>
 2 <title>Flaskr</title>
 3 <link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}">
 4 <body>
 5 <div class=page>
 6     <p>用户名:</p>{{ username }}
 7     <p>年龄:</p>{{ age }}
 8     <p>邮箱:</p>{{ pdell.Email }}
 9     <p>申请时间:</p>{{ pdell.Time }}
10 </div>
11 </body>
View Code

 

posted on 2018-12-10 11:00  阿乐01  阅读(3740)  评论(0编辑  收藏  举报