本文整理汇总了Python中blog.models.BlogPost.edit方法的典型用法代码示例。如果您正苦于以下问题:Python BlogPost.edit方法的具体用法?Python BlogPost.edit怎么用?Python BlogPost.edit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.BlogPost
的用法示例。
在下文中一共展示了BlogPost.edit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_edit
# 需要导入模块: from blog.models import BlogPost [as 别名]
# 或者: from blog.models.BlogPost import edit [as 别名]
def post_edit(request, post_id):
post = BlogPost.get_by_id(int(post_id))
user = users.get_current_user()
if request.method == "GET" and post.author == user.email():
form = BlogPostForm({"title": post.title, "content": post.content})
params = {"form": form, "post": post}
return blog_render(request, "post_edit.html", params)
elif request.method == "POST" and post.author == user.email():
form = BlogPostForm(request.POST)
if form.is_valid():
BlogPost.edit(post_id=int(post_id),
title=form.cleaned_data["title"],
content=form.cleaned_data["content"])
else:
params = {"form": form}
return blog_render(request, "post_add.html", params)
return redirect("home")
else:
return redirect("forbidden")