內容簡介
當你使用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也成為唯一,這樣就好了