为什么 admin 的模板覆盖了 Flask 中的 main 模板?

Why does admin's template cover over main's one in Flask?

这是我的结构。

│  run.py
│
├─admin
│  │  views.py
│  │  views.pyc
│  │  __init__.py
│  │  __init__.pyc
│  │
│  └─templates
│          hello.html
│          index.html
│
└─main
    │  views.py
    │  views.pyc
    │  __init__.py
    │  __init__.pyc
    │
    └─templates
            index.html

我尝试在 Flask 项目中构建两个应用程序。我的目的是当我浏览 http://127.0.0.1:5000/main/ 时它会 returns main/templates/index.html, 当我浏览 http://127.0.0.1:5000/admin/ 时它会 returns main/templates/index.html.

我发现我浏览 http://127.0.0.1:5000/main/ 它将 return main/templates/index.html。 WTF?

如果我在将 main/templates/index.html 更改为 main/templates/index2.html 时重命名不同目录的 html,我将有效地获得我期望的 main/templates/index2.html

admin/views.py:

from flask import Blueprint, render_template
admin = Blueprint("admin", __name__, template_folder="templates")
@admin.route('/')
def index():
    return render_template('index.html')

main/views.py:

from flask import Blueprint, render_template
main = Blueprint("main", __name__, template_folder="templates")
@main.route('/')
def index():
    return render_template('index.html')

run.py

import os
from flask import Flask
from main.views import main
from admin.views import admin

app = Flask(__name__)

app.register_blueprint(main, url_prefix='/main')
app.register_blueprint(admin, url_prefix='/admin')

print app.url_map

app.run(debug=True)

django 中的问题相同。文档推荐你的模板目录应该设置:app_name/templates/app_name.