通過flask,輸出頁面
后端代碼文件:app.py
前端html文件:output.html
1、打開(app.py)
導入相關模塊:

2、定義方法:(app.py)

3、寫入與后端定義好的參數:(output.html)

4、接着就可以看到效果:

通過以上步驟就可以實現:后端傳給前端參數,前端發送到頁面展示。
如果不通過后端傳參數,也可以直接在前端寫數組,並且輸出:
只要在html頁面<body></body>標簽中間加入以下代碼就ok


1 <body> 2 {% for namelist in namelist %} 3 4 {{ namelist }} 5 <br> 6 7 {% endfor %} 8 9 10 <script> 11 var namelist = ['哈哈','嘻嘻','你是最棒的']; 12 for(i=0;i<namelist.length;i++){ 13 document.write(namelist[i]+"<br>") 14 15 } 16 </script> 17 </body>
1 from flask import Flask,render_template 2 app = Flask(__name__) 3 app.config.update(DEBUG=False) 4 5 6 @app.route('/') 7 def hello_world(): 8 return 'Hello World!' 9 10 @app.route('/test') 11 def Shuru(): 12 namelist = ['第一個名字','第二個名字','第三個名字'] #定義一個數組 13 return render_template('output.html',namelist=namelist) 14 15 16 if __name__ == '__main__': 17 app.run()
丸子要加油呀
by:丸子
