本文整理汇总了Python中blog.models.Article.find方法的典型用法代码示例。如果您正苦于以下问题:Python Article.find方法的具体用法?Python Article.find怎么用?Python Article.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Article
的用法示例。
在下文中一共展示了Article.find方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_article
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import find [as 别名]
def edit_article(request, article_slug):
article = Article.find(article_slug)
form = EditArticleForm(request.POST or None, initial=article.to_dict())
if request.POST.get("delete"):
article.key.delete()
return redirect("/")
elif form.is_valid():
article.title = form.cleaned_data["title"]
article.content = form.cleaned_data["content"]
article.last_update = datetime.now()
article.save()
return redirect("/")
return render(request, "form.html", {"form": form})
示例2: view_article
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import find [as 别名]
def view_article(request, article_slug):
article = Article.find(article_slug)
return render(request, "article.html", {"article": article})
示例3: test_delete_article
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import find [as 别名]
def test_delete_article(self):
article = self.create_article()
self.client.post('/admin/edit/%s' % article.slug,
{'delete': True}
)
self.assertFalse(Article.find(article.slug))
示例4: test_add_article
# 需要导入模块: from blog.models import Article [as 别名]
# 或者: from blog.models.Article import find [as 别名]
def test_add_article(self):
self.client.post('/admin/new',
{'title': 'New title', 'content': 'New content'}
)
self.assertTrue(Article.find('new-title'))