【发布时间】:2011-11-02 01:13:09
【问题描述】:
我的烧瓶应用布局是:
myapp/
run.py
admin/
__init__.py
views.py
pages/
index.html
main/
__init__.py
views.py
pages/
index.html
_init_.py 文件为空。 admin/views.py 内容为:
from flask import Blueprint, render_template
admin = Blueprint('admin', __name__, template_folder='pages')
@admin.route('/')
def index():
return render_template('index.html')
main/views.py 类似于 admin/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,
另外,我验证了 main/views.py 中的索引函数按预期调用。 如果我将 main/index.html 重命名为不同的名称,那么它可以工作。所以,没有 重命名,如何实现 1http://127.0.0.1:5000/main/1 显示 main/index.html?
【问题讨论】: