本文整理汇总了Python中models.Blog.blog_content方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.blog_content方法的具体用法?Python Blog.blog_content怎么用?Python Blog.blog_content使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Blog
的用法示例。
在下文中一共展示了Blog.blog_content方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_blog
# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import blog_content [as 别名]
def create_blog(request, id=False):
if request.method == 'POST': # If the form has been submitted...
form = BlogForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
# Process the data in form.cleaned_data
blog_id = int(request.POST['blog_id'])
blog_name = form.cleaned_data['blog_name']
blog_content = form.cleaned_data['blog_content']
if blog_id == False:
# Create blog entity
blog_item = Blog(
blog_name=blog_name,
blog_content=blog_content)
else:
# retrieve existing blog entity
blog_item = ndb.Key(Blog, blog_id).get()
# update existing blog entity
blog_item.blog_name = blog_name
blog_item.blog_content = blog_content
# save request changes
blog_item_key = blog_item.put()
# redirect
return HttpResponseRedirect('/blog') # Redirect after POST
else:
if id == False:
# initialize form that creates form
form = BlogForm() # An unbound form
else:
# fetch the blog item based on the given id
key = ndb.Key(Blog, int(id))
selected_blog = key.get()
# initialize form that edits form
form = BlogForm(initial={
'blog_name': selected_blog.blog_name,
'blog_content': selected_blog.blog_content
})
# produce var for template
variables = RequestContext(request, {
'form' : form,
'blog_id': int(id)
})
return render_to_response( 'create_blog.html', variables )