[Flask] 藍本和 render_template('index.html') 遇到的坑


內容簡介

當你使用flask中的blue實現多個app的時候,會遇到在瀏覽器輸入/app1和/app2時,出現的是完全相同的界面。
本文就是為了解決這個問題。

內容解答

文件路徑
App1
|-- templates
|   |-- index.html
|-- static
|-- views.py
|-- ... more.py
App2
|-- templates
|   |-- index.html
|-- static
|-- views.py
|-- ... more.py

可以參考的鏈接:傳送門1, 傳送門2
url和藍圖綁定,但是render_template可不是,因此使用render_template('index.html')的時候,它不知道是哪一個index,由此產生錯誤。具體詳情可以參考鏈接1.

解決方案

首先更改templates中的路徑,變成app1/templates/app1/index.html
然后修改render_template('app1/index.html'),讓render_template也成為唯一,這樣就好了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM