flask web
1 <!doctype html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Document</title> 6 <link rel="stylesheet" href="css.css"/> 7 </head> 8 <body> 9 <ul> 10 {%for item in nav %} 11 <li>{{item}} </li> 12 {%endfor%} 13 </ul> 14 <br/> 15 <img src="/static/images/xianxing.jpg" alt=""/> 16 17 <hr/> 18 <h3>hello world {{uname}}</h3> 19 <div class="article"> 20 <p>文档列表</p> 21 {{blog}} 22 <p> 23 {%for k,v in blog.items()%} 24 25 <span>{{k}}</span>:<span>{{v}}</span> 26 {%endfor%} 27 </p> 28 </div> 29 </body> 30 </html>
1 __author__ = 'admin' 2 # -*- coding: utf8 -*- 3 4 from flask import Flask, render_template 5 6 app = Flask(__name__) 7 8 9 @app.route('/<name>') 10 def index(name): 11 navList = ['Index', u'新闻', 'IT', 'Culture', 'Music', 'About'] 12 blog = {'title': 'blog title', 'content': 'blog content'} 13 return render_template('index.html', uname=name, nav=navList,blog=blog) 14 15 16 if __name__ == '__main__': 17 app.debug = True 18 app.run(host='0.0.0.0', port=80)