首页 > 解决方案 > jinja2.exceptions.UndefinedError:“分页”未定义

问题描述

即使我定义了分页,为什么会出现此错误?

这是我在 .py 文件中定义它的地方。

@app.route("/library")
def library():
    path = "static/uploads"
    images = os.listdir(path)
    page, per_page, offset = get_page_args(page_parameter='page',
                                           per_page_parameter='per_page')
    total = len(images)
    pagination_images = get_images(images, offset=offset, per_page=per_page)
    pagination = Pagination(page=page, per_page=per_page, total=total,
                            css_framework='bootstrap4')
    return render_template("library.html", 
                           images=pagination_images,
                           page=page,
                           per_page=per_page,
                           pagination=pagination)    

这是我的 library.html 文件中的错误。

File "C:\Users\Henry\anaconda3\Lib\site-packages\jinja2\_compat.py", line 28, in reraise
raise value.with_traceback(tb)
File "C:\Users\Henry\OneDrive\Documents\Website\Website\TrashDetection\templates\library.html", line 1, in top-level template code
{% extends "base.html" %}
File "C:\Users\Henry\OneDrive\Documents\Website\Website\TrashDetection\templates\base.html", line 28, in top-level template code
{% block content %}{% endblock %}
File "C:\Users\Henry\OneDrive\Documents\Website\Website\TrashDetection\templates\library.html", line 10, in block "content"
{{ pagination.links }}
File "C:\Users\Henry\anaconda3\Lib\site-packages\jinja2\environment.py", line 471, in getattr
return getattr(obj, attribute)Open an interactive python shell in this frame
jinja2.exceptions.UndefinedError: 'pagination' is undefined

标签: flask

解决方案


推荐阅读