本文整理汇总了Python中blog.models.Article.get_by_key_name方法的典型用法代码示例。如果您正苦于以下问题:Python Article.get_by_key_name方法的具体用法?Python Article.get_by_key_name怎么用?Python Article.get_by_key_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Article
的用法示例。
在下文中一共展示了Article.get_by_key_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_article
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import get_by_key_name [as 别名]
def get_article(self, slug):
""" Get article
"""
article = Article.get_by_key_name(slug)
if article:
self.response.out.write(template.render(
'blog/templates/article.html', {'article': article}))
else:
self.redirect('/')
示例2: update_article
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import get_by_key_name [as 别名]
def update_article(self, slug):
""" Update existing article
"""
article = Article.get_by_key_name(slug)
if not article:
self.redirect('/')
if not self.request.POST:
self.response.out.write(template.render('blog/templates/edit.html',
{'article': article,
'title': 'Edit article',
'action': webapp2.uri_for('update_article', slug=slug)}))
else:
slug = self.request.get('slug')
article.key_name = slug
article.title = self.request.get('title')
article.description = self.request.get('description')
article.keywords = map(string.strip,
self.request.get('keywords').split(','))
article.content = self.request.get('content')
article.put()
self.redirect('/' + slug)
示例3: create_article
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import get_by_key_name [as 别名]
def create_article(self):
""" Create new article
"""
if not self.request.POST:
self.response.out.write(template.render('blog/templates/edit.html',
{'article': None,
'title': 'New article',
'action': webapp2.uri_for('create_article')}))
else:
slug = self.request.get('slug')
article = Article.get_by_key_name(slug)
if article:
slug = slug + '_to_change'
keywords = map(string.strip,
self.request.get('keywords').split(','))
article = Article(key_name=slug,
title=self.request.get('title'),
description=self.request.get('description'),
keywords=keywords,
content=self.request.get('content'))
article.put()
self.redirect('/' + slug)