1. 程式人生 > 其它 >Python-flask-render_template()函式

Python-flask-render_template()函式

技術標籤:python-flask-html 表格問題

#run.py檔案
from flask import Flask, render_template
app = Flask(__name__)


@app.route("/")
def template_test():
    return render_template('template.html', my_string="Wheeeee!", my_list=[0,1,2,3,4,5])
result=app.template_test()
print(result)
# if __name__ == '__main__':
# app.run(debug=True)在這裡插入程式碼片
<!DOCTYPE html>
<html>
  <head>
    <title>Flask Template Example</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" media="screen">
<style type="text/css"> .container { max-width: 500px; padding-top: 100px; } </style> </head> <body> <div class="container"> <p>My string: {{my_string}}</p> <p>Value from the list: {{
my_list[3]}}</p> <p>Loop through the list:</p> <ul> {% for n in my_list %} <li>{{n}}</li> {% endfor %} </ul> </div> <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script> <script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script> </body> </html>在這裡插入程式碼片

在這裡插入圖片描述
最終結果
在這裡插入圖片描述