视频每评论一次,播放次数为什么会增加2
来源:11-2 .收藏电影1
wa666
2017-08-17
@home.route("/play/<int:id>/<int:page>/", methods=["GET", "POST"]) def play(id=None, page=None): movie = Movie.query.join(Tag).filter( Tag.id == Movie.tag_id, Movie.id == int(id) ).first_or_404() if page is None: page = 1 page_data = Comment.query.join( Movie ).join( User ).filter( Movie.id == movie.id, User.id == Comment.user_id ).order_by( Comment.addtime.desc() ).paginate(page=page, per_page=10) movie.playnum = movie.playnum + 1 form = CommentForm() if "user" in session and form.validate_on_submit(): data = form.data comment = Comment( content=data["content"], movie_id=movie.id, user_id=session["user_id"] ) db.session.add(comment) db.session.commit() movie.commentnum = movie.commentnum + 1 db.session.add(movie) db.session.commit() flash("添加评论成功!", "ok") return redirect(url_for('home.play', id=movie.id, page=1)) db.session.add(movie) db.session.commit() return render_template("home/play.html", movie=movie, form=form, page_data=page_data)
看视频中和自己操作的都是评论一次播放次数增加2,刷新页面只会增加1,按理说评论后路由到当前页面也只会加1,这是为什么呢
写回答
1回答
-
同学,你好,顺序的问题,你这样改一下试试:
form = CommentForm() if "user" in session and form.validate_on_submit(): data = form.data comment = Comment( content=data["content"], movie_id=movie.id, user_id=session["user_id"] ) db.session.add(comment) db.session.commit() movie.commentnum = movie.commentnum + 1 db.session.add(movie) db.session.commit() flash("添加评论成功!", "ok") return redirect(url_for('home.play', id=movie.id, page=1)) movie.playnum = movie.playnum + 1 db.session.add(movie) db.session.commit()
012017-08-17
相似问题