Flask在引用蓝图页面时为html文件中的url_提供未定义的错误

Flask在引用蓝图页面时为html文件中的url_提供未定义的错误,flask,undefined,url-for,Flask,Undefined,Url For,我尝试构建一个web应用程序,在导航菜单栏中,当我尝试打开localhost/(因此,@app.route('/')和base.html)时,我收到注册蓝图的未定义错误。有人能帮我吗 初始化.py from flask import ( Flask, render_template) from .database import DB def create_app(test_config=None): # create and configure the app app

我尝试构建一个web应用程序,在导航菜单栏中,当我尝试打开localhost/(因此,
@app.route('/')
base.html
)时,我收到注册蓝图的未定义错误。有人能帮我吗

初始化.py

from flask import (
    Flask, render_template)
from .database import DB


def create_app(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config["MONGO_URI"] = "mongodb://localhost:27017/chpalinka"
    DB.init()

    # a simple page that says hello
    @app.route('/')
    def home():
        return render_template('base.html')

    from . import jegyzokonyv
    app.register_blueprint(jegyzokonyv.bp)

    return app
杰吉佐科尼酒店

import functools

from flask import (
    Blueprint, flash, g, redirect, render_template, request, session, url_for
)
from .database import DB


bp = Blueprint('jegyzokonyv', __name__, url_prefix='/jegyzokonyv')

@bp.route('/cefrezes', methods=('GET', 'POST'))
def cefrezes():
    jegyzokonyvek = DB.get_all('cefreze')
    return render_template('jegyzokonyv.html', query=jegyzokonyvek)

@bp.route('/fozes', methods=('GET', 'POST'))
def fozes():
    pass

@bp.route('/erleles', methods=('GET', 'POST'))
def erleles():
    pass
以及base.html的导航部分

<nav class="mt-2">
    <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
        <!-- Add icons to the links using the .nav-icon class
                 with font-awesome or any other icon font library -->
        <li class="nav-item">
            <a href="#" class="nav-link active">
                <i class="nav-icon fas fa-tachometer-alt"></i><p>Kezdőlap</p></a>
        </li>
        <li class="nav-header">Jegyzőkönyvek</li>
        <li class="nav-item"><a href="{{ url_for(jegyzokonyv.cefrezes) }}" class="nav-link">
            <i class="nav-icon fa fa-filter"></i><p>Cefrézés</p></a>
        </li>
        <li class="nav-item"><a href="{{ url_for(jegyzokonyv.fozes) }}" class="nav-link">
            <i class="nav-icon fa fa-tint"></i><p>Főzés</p></a>
        </li>
        <li class="nav-item"><a href="{{ url_for(jegyzokonyv.erleles) }}" class="nav-link">
            <i class="nav-icon fa fa-cogs"></i><p>Érlelés</p></a>
        </li>
    </ul>
</nav>

  • Jegyzőkönyvek
aa和错误消息:

  File "D:\WebPages\Palinka_Flask\flaskr\templates\base.html", line 183, in top-level template code
    <li class="nav-item"><a href="{{ url_for(jegyzokonyv.cefrezes) }}" class="nav-link">
  File "D:\WebPages\Palinka_Flask\venv\lib\site-packages\jinja2\environment.py", line 430, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'jegyzokonyv' is undefined
文件“D:\WebPages\Palinka\u Flask\flaskr\templates\base.html”,第183行,在顶级模板代码中
  • 文件“D:\WebPages\Palinka\u Flask\venv\lib\site packages\jinja2\environment.py”,第430行,在getattr中 返回getattr(对象,属性) jinja2.exceptions.UndefinedError:“jegyzokonyv”未定义
  • 的url\u接受字符串。将模板中(jegyzokonyv.cefrezes)的
    url_更改为('jegyzokonyv.cefrezes')