代码架构:flask +mysql
在测试分页现实的时候出现问题,分页只能显示前5页(显示都正常),第六页后就会提示报错,最后一页也会报错。
浏览器报错:
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
> File "D:\code5\k1fzwq\ven\lib\site-packages\flask\helpers.py", line 357, in url_for
> rv = url_adapter.build(
> File "D:\code5\k1fzwq\ven\lib\site-packages\werkzeug\routing.py", line 2314, in build
> raise BuildError(endpoint, values, method, self)
> werkzeug.routing.BuildError: Could not build url for endpoint 'admin.adminloginlog_list'. Did you forget to specify values ['page']?
> 127.0.0.1 - - [27/Dec/2021 20:35:21] "GET /admin/adminloginlog/list/6/ HTTP/1.1" 500 -
>
> Process finished with exit code 0
# 管理员登录日志
admin.route("/adminloginlog/list/<int:page>/", methods=["GET"])
admin_login_req
# @admin_auth
def adminloginlog_list(page=None):
if page is None:
page = 1
page_data = Adminlog.query.join(
Admin
).filter(
Admin.id == Adminlog.admin_id,
).order_by(
Adminlog.addtime.desc()
).paginate(page=page, per_page=1)
return render_template("admin/adminloginlog_list.html", page_data=page_data)
# 会员登录日志
class Userlog(db.Model):
__tablename__ = "userlog"
id = db.Column(db.Integer, primary_key=True) # 编号
user_id = db.Column(db.Integer, db.ForeignKey('user.id')) # 所属会员
ip = db.Column(db.String(100)) # 登录IP
addtime = db.Column(db.DateTime, index=True, default=datetime.now) # 登录时间
def __repr__(self):
return "<Userlog %r>" % self.id