Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取最后20条记录并显示最后一个寄存器_Python_Flask_Flask Sqlalchemy_Flask Mysql - Fatal编程技术网

Python 获取最后20条记录并显示最后一个寄存器

Python 获取最后20条记录并显示最后一个寄存器,python,flask,flask-sqlalchemy,flask-mysql,Python,Flask,Flask Sqlalchemy,Flask Mysql,所以我有个问题,我不知道怎么去找他 @app.route('/',methods=['GET', 'POST']) def index(): if current_user.is_authenticated: current_user.update_on = datetime.utcnow() db.session.add(current_user) db.session.commit() username = db.session

所以我有个问题,我不知道怎么去找他

@app.route('/',methods=['GET', 'POST'])
def index():
    if current_user.is_authenticated:
        current_user.update_on = datetime.utcnow()
        db.session.add(current_user)
        db.session.commit()
    username = db.session.query(User.username,User.avatar).order_by(User.username,User.avatar).limit(20).all()
    nicks = [x[0]for x in username]
    base = 'http://localhost:5000/profil'
    urls = ['{}/{}'.format(base,n)for n in nicks]
    return render_template("index.html",user = username,urls=urls,nicks=nicks)
这是我在app.py中的代码,所以我想从mysql中获取最后20条记录,并用html显示最后的记录。最后一个注册用户将首先显示,最后一个是第二个。。。但在html中显示随机用户。 我的HTML文件:

这:

按用户名和头像订购。将其更改为:

username = db.session.query( \
    User.username,User.avatar).order_by(User.update_on.desc(),User.username).limit(20).all()

改为在上次更新时间之前订购。

您能告诉我为什么User.update\u启用了“订购者”吗?此列显示上次在上看到用户的时间website@Tshibe然后按user.created.desc排序,…-将创建的列替换为保存您在xx.xx.xxxx日期注册的列。我按照您在顶部所说的那样做,但仍然不起作用,请给我显示一个随机用户密钥,现在它起作用了,忘了它吧。desc但如果您能帮我解决“查询过程中与MySQL服务器的连接丢失”问题,请将其连接到快速端
DATABASE_URI = 'mysql://{}:{}@{}:{}/kamilos98'.format(config['user'], config['password'],config['host'], config['port'])
app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
username = db.session.query( \
    User.username,User.avatar).order_by(User.username,User.avatar).limit(20).all()
username = db.session.query( \
    User.username,User.avatar).order_by(User.update_on.desc(),User.username).limit(20).all()