我的瓶的應用程序佈局是:燒瓶藍圖模板文件夾
myapp/
run.py
admin/
__init__.py
views.py
pages/
index.html
main/
__init__.py
views.py
pages/
index.html
_ 初始化 _ .py文件是空的。 管理員/ views.py內容是:
from flask import Blueprint, render_template
admin = Blueprint('admin', __name__, template_folder='pages')
@admin.route('/')
def index():
return render_template('index.html')
主/ views.py類似於管理員/ views.py:
from flask import Blueprint, render_template
main = Blueprint('main', __name__, template_folder='pages')
@main.route('/')
def index():
return render_template('index.html')
run.py是:
from flask import Flask
from admin.views import admin
from main.views import main
app = Flask(__name__)
app.register_blueprint(admin, url_prefix='/admin')
app.register_blueprint(main, url_prefix='/main')
print app.url_map
app.run()
現在,如果我訪問http://127.0.0.1:5000/admin/
,它正確顯示admin/index.html。 但是,http://127.0.0.1:5000/main/
仍顯示admin/index.html而不是main/index.html。我查app.url_map:
<Rule 'admin' (HEAD, OPTIONS, GET) -> admin.index,
<Rule 'main' (HEAD, OPTIONS, GET) -> main.index,
此外,我驗證了主/ views.py該索引功能按預期的方式調用。 如果我將main/index.html重命名爲不同的東西,那麼它可以工作。所以,如果沒有 重命名,那麼如何實現1http://127.0.0.1:5000/main/1顯示main/index.html?
有類似的問題。我希望這個處理方式不同。更改靜態文件夾的位置對於服務文件來說工作得很好,但如果同一個文件已存在,模板將被覆蓋。 –
正如jay chan指出的,最簡單的方法是將模板存儲在主模板文件夾中,以便將admin.html存儲在'myapp/templates/admin/index.html'下。 –
爲什麼不更改'template_folder'到'「admin/pages」或'「main/pages」'? –