找回密碼
 註冊
搜索
查看: 799|回復: 0

[教學] Flask模板+list操作+dict操作+過濾器+loop變量

[複製鏈接]
發表於 2025-6-5 19:14:22 | 顯示全部樓層 |閱讀模式
Push to Facebook
一.模板渲染:

二.list操作取值:

三.內建loop循環變數:

四.常用的過濾器:

1.list列表操作:

五.字典dict的操作:

run.py 內容
  1. @app.route("/", methods=['GET'])
  2. def index():
  3. 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': ''}]
  4. return render_template("public/index.html",sm_classes=sm_classes)
複製代碼

index.html
  1. {% for sm_class in sm_classes %}
  2.                     <li><a href="{{ny_root_path}}/statelist?cid={{sm_class.cid}}">{{sm_class.name}}</a></li>
  3.                                         {/section}-->
  4.                     {% endfor %}
複製代碼


展示圖:

Flask 模板 list dict loop

 Flask 模板 list dict loop


文章出處: NetYea 網頁設計, 慧晟數位科技, 網站架設


https://www.youtube.com/watch?v=APh3jdVryF0
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|小黑屋|TShopping

GMT+8, 2025-6-15 07:27 , Processed in 0.023117 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回復 返回頂部 返回列表