蓝图的另一个烧瓶模板问题

问题描述 投票:0回答:1

我有一个像这样的 Flask 蓝图包结构:

application/
   -- __init__.py
   -- extensions.py
   -- authentication/
      -- templates/
         -- register.html
      -- __init__.py
      -- views.py
templates/
   -- base.html
static/
main.py
database.db

在我的

authentication/__init__.py
中:

from flask import Blueprint

authentication = Blueprint("authentication", __name__, template_folder="templates")

from . import views

在我的

authentication/views.py
中:

# REGISTER PAGE
@authentication.route('/register', methods=['GET', 'POST'])
def register():
    ...
    return render_template("register.html", form=form)

在我的

app/__init__.py
中:

def create_app():
    # INSTANTIATE APP
    app = Flask(__name__)
    ...
    app.register_blueprint(authentication, url_prefix="/")
    ...

有人知道哪里出了问题吗?为什么我会在注册页面上看到

jinja2.exceptions.TemplateNotFound: base.html

我已经尝试做所有的事情,比如停止和重新启动,把

base.html
放在
authentication.templates
作品中,但是一旦它在
root.templates
中,它就被写成找不到。

html flask jinja2
1个回答
0
投票

Flask 仅在您的应用程序文件夹中搜索模板。如果您想更改位置,可以使用此问题中列出的方法:How to reference a html template from a different directory in python flask

© www.soinside.com 2019 - 2024. All rights reserved.