本文整理汇总了Python中models.Post.get_id方法的典型用法代码示例。如果您正苦于以下问题:Python Post.get_id方法的具体用法?Python Post.get_id怎么用?Python Post.get_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Post
的用法示例。
在下文中一共展示了Post.get_id方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get_id [as 别名]
def get(self, idx=''):
u = self.check_login()
params = { 'user': u }
if idx and not Post.get_id(int(idx)):
self.error(404)
return
params['posts'] = [Post.get_id(int(idx))] if idx else Post.get_last(10)
self.render('home.html', **params)
示例2: get
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get_id [as 别名]
def get(self, idx=''):
if idx:
r = Post.get_id(int(idx)).as_dict()
else:
r = [x.as_dict() for x in Post.get_all()]
p = Post.get_id(int(idx)) if idx else Post.get_all()
self.response.headers['Content-Type'] = 'application/json; charset=utf-8'
self.response.out.write(json.dumps(r))
示例3: post
# 需要导入模块: from models import Post [as 别名]
# 或者: from models.Post import get_id [as 别名]
def post(self, post_id=None):
if self.user:
title = self.request.get('subject')
content = self.request.get('content')
if title and content:
# if editing, there will be a post_id defined
if post_id:
post = self.get_post(post_id)
print self.user.get_id() == int(post.owner_id)
if post and self.user.get_id() == int(post.owner_id):
post.title = title
post.content = content
post.put()
self.redirect(HOME_PATH + '/' +
str(post.get_id()) + '/')
else:
self.redirect_to_login()
else:
# create a new post
post = Post(title=title, content=content, owner_id=str(
self.user.get_id()), owner=self.user.key)
post.put()
self.redirect(HOME_PATH + '/' + str(post.get_id()) + '/')
else:
title_error = ''
content_error = ''
if not title:
title_error = 'Title is required!'
if not content:
content_error = 'Content is required!'
self.render_form(
title, content, title_error=title_error, content_error=content_error)
else:
self.redirect_to_login()