本文整理汇总了Python中models.comment.Comment.by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Comment.by_id方法的具体用法?Python Comment.by_id怎么用?Python Comment.by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.comment.Comment
的用法示例。
在下文中一共展示了Comment.by_id方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decorated_function
# 需要导入模块: from models.comment import Comment [as 别名]
# 或者: from models.comment.Comment import by_id [as 别名]
def decorated_function(self, *args, **kwargs):
comment_id = args[1]
comment = Comment.by_id(comment_id)
if comment:
kwargs['comment'] = comment
return f(self, *args, **kwargs)
else:
self.error(404)
return
示例2: post
# 需要导入模块: from models.comment import Comment [as 别名]
# 或者: from models.comment.Comment import by_id [as 别名]
def post(self, comment_id):
if self.user:
username = self.user.name
commentid = int(comment_id)
comment = Comment.by_id(commentid)
if comment.created_by == username:
comment.delete()
self.redirect('/comment')
else:
error = "You can only delete comments created by you"
self.render("delete-comment.html", comment=comment,
error=error)
else:
self.redirect('/login')
示例3: get
# 需要导入模块: from models.comment import Comment [as 别名]
# 或者: from models.comment.Comment import by_id [as 别名]
def get(self, comment_id):
if self.user:
commentid = int(comment_id)
comment = Comment.by_id(commentid)
if not comment:
self.error(404)
return
if self.user.name == comment.created_by:
self.render_front(comment.title, comment.content)
else:
error = "You can only edit comments you created"
self.render_front(error=error)
else:
self.redirect('/login')