码迷,mamicode.com
首页 > 编程语言 > 详细

python的一些总结3

时间:2015-08-04 15:02:33      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

好吧 刚刚的2篇文章都很水。。

这篇 也是继续水

在 templates 右键新建 html 文件:如 index.html (输入以下代码)

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title></title>
 6 </head>
 7 <body>
 8 
 9 {{ test }}
10 </body>
11 </html>

注意 除了{{test}} 其他 都是 自动生成。

回到 xxx.py 文件 修改 hello_world 方法:

如下:

 1 #encoding=utf-8
 2 from flask import Flask, render_template,jsonify,render_template_string
 3 
 4 app = Flask(__name__)
 5 
 6 
 7 @app.route(/)
 8 def hello_world():
 9     #return ‘Hello World!‘
10     #return jsonify({‘key‘:‘hello‘}) #返回json
11     #return render_template_string(‘<html><head></head><body>1111:{{test}}</body></html>‘,test="tttt") #通过拼接字符串方式
12     return render_template(index.html, test="tttttt") #普通返回 view 方式
13 
14 
15 if __name__ == __main__:
16     app.run(debug=True)

如 代码 view 中{{test}} 为 打印 test,需要 后代返回 view时 传递参数test

python的一些总结3

标签:

原文地址:http://www.cnblogs.com/rufus-hua/p/4701772.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!