flask - 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
解决方案
推荐阅读
- android - Android Studio 3.2 - 加载小部件时出现问题
- vba - VBA认为某个键被按下
- android - 片段中的广播接收器称为 3 次仅发送一次
- android - 在 Appcelerator Titan 中将 blob 转换为位图图像
- vba - VBA如何在函数中替换“As Any”
- elasticsearch - 导入 Kibana 仪表板时出错:无法创建 Kibana 加载程序:创建 Kibana 客户端时出错
- c# - 仅在 VS 调试模式下解决 SQL 查询超时
- javascript - 如何解决网页错误消息:未捕获的引用错误
- python - 神经网络感知器算法 Sklearn
- javascript - navigator.geolocation.getCurrentPosition 大约需要 30 - 40 秒才能获得 js 中的位置