def addcomment(): form = CommentForm() error = 'Sorry, Post Comments Error!' if form.validate_on_submit(): comment = Comment(author_ip=request.environ['HTTP_X_FORWARDED_FOR']) form.populate_obj(comment) db.session.add(comment) post = Post.query.getpost_id(comment.post_id) post.comment_count += 1 db.session.commit() return redirect(url_for('article', postid=comment.post_id)) return render_template('/error.html', content=error)