Python Flask: 邮件列表
来自CloudWiki
初始版
python端
from flask import Flask,render_template app = Flask(__name__) @app.route('/list') def show_list(): thelist =[{"id":1,"name":"cloud1","url":"/detail/1"}, {"id":2,"name":"cloud2","url":"/detail/2"}, {"id":3,"name":"cloud3","url":"/detail/3"} ] return render_template('list2.html',mylist =thelist) @app.route('/email-list') def show_email_list(): thelist =[{"sender": "zhangsan@qq.com", "receiver":"maxin5452@qq.com", "subject":"this is a test mail 1" }, {"sender": "zhangsan@qq.com", "receiver":"maxin5452@qq.com", "subject":"this is a test mail 2" }, {"sender": "zhangsan@qq.com", "receiver":"maxin5452@qq.com", "subject":"this is a test mail3" }, ] #return str(thelist) return render_template('email-list.html',mylist =thelist) @app.route('/detail/<int:id>') def instance_detail(id): #return "主机详情:"+str(id) return render_template('detail3.html',myid=id) if __name__ == '__main__': app.run( host='0.0.0.0',port="5004",debug="true")
html模板
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <h1>the authors are:</h1> <table class="table table-striped"> <tr> <th>id</th> <th>sender</th> <th>reveicer</th> <th>subjuct</th> </tr> {% for i in mylist %} <tr> <td>0</td><td>{{i.sender}}</td><td>{{i.receiver}}</td><td>{{i.subject}}</td> </tr> {% endfor %} </table> </body> </html>