评论数量不会增加?
来源:11-1 .电影评论-统计

戴晶kyle
2017-12-22
#播放 @home.route('/play/<int:id>/<int:page>/',methods=['GET','POST']) # @user_login_req def play(id=None,page=None): movie=Movie.query.join(Tag).filter( Movie.tag_id==Tag.id, Movie.id==int(id) ).first_or_404() if page is None: page=1 page_data=Comment.query.join(User).filter( Comment.movie_id==id, Comment.user_id==User.id, ).order_by(Comment.addtime.desc()).paginate(page=page,per_page=2) movie.playnum += 1 form=CommentForm() if form.validate_on_submit()and 'user' in session: data=form.data comment=Comment( content=data['content'], movie_id=int(id), user_id=session['user_id'], ) db.session.add(comment) db.session.commit() movie.commentnum+=1 flash('添加评论成功!','ok') return redirect(url_for('home.play',id=id,page=1)) db.session.add(movie) db.session.commit() return render_template('home/play.html',movie=movie,form=form,page_data=page_data)
老师,添加评论后数据库中commentnum并不会增加,一直为0??
写回答
3回答
-
SuperDi
2018-12-12
老师代码写的有错误
00 -
SuperDi
2018-12-12
去掉return redirect(url_for('home.play',id=id,page=1))
00 -
Grant_Lian
2017-12-23
还需要commit一次吧,
db.session.add(comment)
movie.commentnum+=1
db.session.commit()
这样弄一下
00
相似问题
评论数量好像没有更新,这是为什么呢?
回答 1
视频每评论一次,播放次数为什么会增加2
回答 1
删除评论的时候,外键的内容会一起删除吗?
回答 1
标签存入数据库不成功
回答 1
为什么不能评论?
回答 1