diff --git a/project/main.py b/project/main.py index 047677f..4993402 100644 --- a/project/main.py +++ b/project/main.py @@ -43,6 +43,14 @@ def manage(): @login_required def chat(): if current_user.isActivated: + if request.args.get("act") == "get_history": + chats_desc = Conversation.query.filter_by( + userid=current_user.id, useremail=current_user.email).order_by(Conversation.datetime.desc()).limit(20).all() + msgs = [] + for chat in reversed(chats_desc): + msgs.append( + {"request": chat.request, "response": chat.response, "datetime": chat.datetime}) + return msgs return render_template('chat.html', user=current_user) else: flash("您的账户暂未被激活") diff --git a/project/templates/chat.html b/project/templates/chat.html index 79d6507..488c573 100644 --- a/project/templates/chat.html +++ b/project/templates/chat.html @@ -38,6 +38,40 @@ });