def play(movie_id=None, page=None): if page is None: page = 1 movie = Movie.query.get_or_404(movie_id) page_data = Comment.query.filter_by(movie_id=movie_id).paginate( page=page, per_page=current_app.config['PER_PAGE']) form = CommentForm() if form.validate_on_submit(): comment = Comment() comment.movie_id = movie_id comment.user_id = current_user.id with db.auto_commit(): movie.comment_num += 1 comment.add(form) return redirect(url_for('home.play', movie_id=movie.id, page=1)) with db.auto_commit(): movie.play_num += 1 return render_template('home/play.html', movie=movie, form=form, page_data=page_data)