def view(id): '''记录用户浏览次数''' redis_data.zincrby('visited:article', 'article:%s' % str(id), 1) comment_form = CommentForm() article = Articles.load_by_id(id) tags = article.tags return render_template('blog/blog_page.html', article=article, tags=tags, comment_form=comment_form)
def view(id): '''记录用户浏览次数''' redis_data.zincrby('visited:article', 'article:%s' % str(id), 1) comment_form = CommentForm() reply_form = ReplyForm() article = Articles.load_by_id(id) all_tags = Tags.query.distinct(Tags.name).all() tags = article.tags return render_template('blog/blog_page.html', article=article, all_tags=all_tags, tags=tags, comment_form=comment_form, reply_form=reply_form)
def comment(id): '''评论表单''' if not writer_permission.can(): flash(_('You have not confirm your account')) return redirect(url_for('blog.index_num')) form = CommentForm() if form.validate_on_submit() and request.method == "POST": post_comment = Comments(author=current_user.username, content=form.comment.data) post_comment.articles_id = id post_comment.publish = datetime.now() db.session.add(post_comment) db.session.commit() return redirect(url_for('blog.view', id=id, _anchor='comment')) return redirect(url_for('blog.view', id=id, _anchor='comment'))
def post(self, blogId): user = request.user form = CommentForm() if form.validate_on_submit(): comment = Comment() comment.content = form.content.data comment.blog_id = blogId comment.author = user db.session.add(comment) db.session.commit() return redirect( url_for( 'blog.blog', blogId=blogId, _anchor='blog-comment')) return redirect( url_for( 'blog.blog', blogId=blogId, _anchor='blog-comment'))
def __init__(self): super(MethodView, self).__init__() self.form = CommentForm()