本文整理汇总了Python中models.Comment.author_name方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.author_name方法的具体用法?Python Comment.author_name怎么用?Python Comment.author_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Comment
的用法示例。
在下文中一共展示了Comment.author_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: postComment
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import author_name [as 别名]
def postComment(article_id):
article = Article.get_by_id(article_id)
if not article:
return "", 404, {"Content-Type": "application/json"}
data = request.get_json()
if not data:
return "Missing data", 400
comment = Comment()
comment.article = article.key
comment.author_name = escape(data.get("author_name"))
comment.author_email = escape(data.get("author_email"))
comment.content = escape(data.get("content"))
comment.put()
comments = Comment.query().order(Comment.date).fetch(keys_only=True)
if len(comments) >= 10:
comments[0].delete()
return serialize(comment)
示例2: post
# 需要导入模块: from models import Comment [as 别名]
# 或者: from models.Comment import author_name [as 别名]
def post(self, title):
post = yield Post.asyncQuery(title=title).first()
if not post:
raise tornado.web.HTTPError(404)
if self.form.validate():
comment = Comment()
comment.create_time = datetime.datetime.utcnow()
comment.author_name = self.form.author_name.data
comment.author_email = self.form.author_email.data
comment.author_url = self.form.author_url.data
# Direct use user post data is unsafe,
# so we convert `org_markdown_text` in the back-end
comment.content = markdown2.markdown(self.form.content.data)
post.comments.append(comment)
yield post.save()
self.flash("评论提交成功~")
return self.redirect("{path}{id}".format(
path=self.request.path, id="#comment"))
self.render("post.html", post=post, form=self.form)