我的瓶的应用程序布局是:烧瓶蓝图模板文件夹
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”'? –