def edit_comment(post_id, comment_id): user = User.query.filter_by(username=current_user.username).first_or_404() comment = Comment.query.filter_by(id=comment_id).first_or_404() if user.id != comment.user_id: # Check user is allowed to edit comment return redirect(url_for('perm_error')) form = CommentForm() if form.validate_on_submit(): comment.body = form.body.data comment.timestamp = datetime.utcnow() db.session.commit() flash('Your changes have been saved.') return redirect(url_for('post', post_id=post_id)) elif request.method == 'GET': # on arrival fill the page values form.fill_form(comment_id) return render_template('edit_comment.html', title="Edit Comment", form=form)