|
一.模板渲染:
二.list操作取值:
三.內建loop循環變數:
四.常用的過濾器:
1.list列表操作:
五.字典dict的操作:
run.py 內容
- @app.route("/", methods=['GET'])
- def index():
- sm_classes = [{'cid': 1, 'num': 2, 'name': '項目介紹', 'img': ''}, {'cid': 4, 'num': 4, 'name': '常見問題', 'img': ''}, {'cid': 3, 'num': 5, 'name': '關於我們', 'img': ''}, {'cid': 31, 'num': 6, 'name': '網頁 教學', 'img': ''}]
- return render_template("public/index.html",sm_classes=sm_classes)
複製代碼
index.html
- {% for sm_class in sm_classes %}
- <li><a href="{{ny_root_path}}/statelist?cid={{sm_class.cid}}">{{sm_class.name}}</a></li>
- {/section}-->
- {% endfor %}
複製代碼
展示圖:
Flask 模板 list dict loop
文章出處: NetYea 網頁設計, 慧晟數位科技, 網站架設
https://www.youtube.com/watch?v=APh3jdVryF0
|
|