【发布时间】:2019-01-04 14:33:03
【问题描述】:
我想找出用户在文章页面上花费的时间。
我有显示文章列表的页面,当您单击该页面中的任何文章时,它将显示该文章的内容。
现在我有文章路线的以下代码
@app.route("/post/<post_id>")
def post(post_id):
post = mongo.db.articles
sp = post.find_one({'_id': ObjectId(post_id)})
##################
userhistory = mongo.db.userhistory
history = {'id' :ObjectId(post_id),'title':sp['Heading'],'User':current_user.user_json['email'],'DateTime':datetime.now()}
userhistory.insert(history)
############################################
#sp = post.find_one({'_id':post_id})
return render_template('post.html', title=post.title, post=sp)
我想计算用户在该特定文章上花费的时间并将其添加到 MongoDB 集合(用户历史记录)中。因此,当用户阅读完文章并再次点击浏览器时,它应该计算所花费的时间。
请帮忙
【问题讨论】:
-
那篇文章中提到的用户花费的时间,还是你想通过脚本计算?
-
我正在考虑通过脚本计算