我的烧瓶应用程序布局是:
myapp/
run.py
admin/
__init__.py
views.py
pages/
index.html
main/
__init__.py
views.py
pages/
index.html
_init_.py 文件为空。管理/视图.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类似于管理/视图.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 is:
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,
另外,我验证了 main/views.py 中的索引函数按预期调用。
如果我将 main/index.html 重命名为不同的名称,那么它就可以工作。所以,没有
重命名,如何实现1http://127.0.0.1:5000/main/1显示main/index.html?