当前位置: 首页>>代码示例>>Python>>正文


Python Blog.put方法代码示例

本文整理汇总了Python中models.Blog.put方法的典型用法代码示例。如果您正苦于以下问题:Python Blog.put方法的具体用法?Python Blog.put怎么用?Python Blog.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Blog的用法示例。


在下文中一共展示了Blog.put方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Post

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import put [as 别名]
    def Post(self):
        title = self.Request.get("title")
        content = self.Request.get("content")

        blog = Blog(title=title, content=content)
        blog.put()
        return webapp2.redirect("/blog")
开发者ID:hackrole,项目名称:GAE_project,代码行数:9,代码来源:blog.py

示例2: post

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import put [as 别名]
    def post(self):
        update = self.request.get('update', False)
        cate_name = self.request.get('cate_name')
        tags_list = self.request.get_all('tags_name', [])
        title = self.request.get('title')
        blog = self.request.get('blog')
        if not blog:
            self.response.write('blog content empty!')

        cate = Category.query(Category.title==cate_name).get()
        if not cate:
            cate = Category(title=cate_name)
            cate.put()
        print tags_list
        tags = Tag.query(Tag.title.IN(tags_list)).fetch()
        tags_old = [tag.title for tag in tags]
        tags_new = []
        for tag in tags_list:
            if tag not in tags_old:
                tag = Tag(title=tag)
                tag.put()
                tags_new.append(tag)
        print tags
        print tags_new
        tags += tags_new
        print tags
        print '==='
        print dir(tags[0])
        tags = [tag.key for tag in tags]

        blog = Blog(title=title, text=blog, category=cate.key, tags=tags)
        blog.put()
        self.response.write('blog publish success')
        self.response.set_status(200)
开发者ID:hackrole,项目名称:gblog,代码行数:36,代码来源:blog.py

示例3: add_entry

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import put [as 别名]
def add_entry():
    if not session.get('logged_in'):
        abort(401)
    blog = Blog()
    blog.title = cgi.escape(request.form['title'])
    blog.text = cgi.escape(request.form['text'])
    blog.put()
    flash('New entry was successfully posted')
    return redirect(url_for('show_entries'))
开发者ID:miquelet,项目名称:flask_projects,代码行数:11,代码来源:app.py

示例4: testdb_init

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import put [as 别名]
def testdb_init():
    # db clear
    t1 = Tag(title="emacs")
    t2 = Tag(title="python")
    t1.put()
    t2.put()

    c1 = Category(title='program')
    c2 = Category(title='edit')
    c1.put()
    c2.put()

    b1 = Blog(title='first blog')
    b1.context = "this is my first blog, hello world"
    b1.put()
    b2 = Blog(title="second blog")
    b2.context = "this is my second blog, hello python"
    b2.tags = [t1.key, t2.key]
    b2.put()
    b3 = Blog(title="third blog")
    b3.context = "this is my third blog, hello python"
    b3.tags = [t1.key,]
    b3.category = c2.key
    b3.put()
    b4 = Blog(title="fourth blog")
    b4.context = "this is my fourth blog, hello python"
    b4.tags = [t2.key,]
    b4.category = c1.key
    b4.put()
开发者ID:hackrole,项目名称:gblog,代码行数:31,代码来源:fts.py

示例5: post

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import put [as 别名]
  def post(self):
    """
    Post method to create new posts
    :rtype: object
    """
    blog = {}
    _title = self.request.get("title")
    _blog = self.request.get("blog")
    _title_error = "Please enter title"
    _post_error = "Please enter post"

    if self.user:
      if _title and _blog:
        user = self.user
        newPost = Blog(user=user.key, title=_title, blog=_blog)
        newPost_key = newPost.put()
        newPostID = newPost_key.id()
        self.redirect('/blog/%s' % str(newPostID))
      elif _title == "" or _blog == "":
        if _title == "":
          blog["title"] = ""
          blog["blog"] = _blog
          self.render('newpost.html', title_error=_title_error, blog=blog)
        if _blog == "":
          blog["title"] = _title
          blog["blog"] = ""
          self.render('newpost.html', post_error=_post_error, blog=blog)
    else:
      self.redirect('/login')
开发者ID:manpreet07,项目名称:multi-user-blog,代码行数:31,代码来源:blog.py

示例6: create_blog

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import put [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 )
开发者ID:leiksu,项目名称:appengine-project,代码行数:52,代码来源:views.py

示例7: setUp

# 需要导入模块: from models import Blog [as 别名]
# 或者: from models.Blog import put [as 别名]
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()

        tag1 = Tag(title='emacs')
        tag2 = Tag(title='vim')
        tag1.put()
        tag2.put()
        cate = Category(title='emacs笔记')
        cate.put()
        b1 = Blog(title="the first emacs blog", context="hello, world",
                  category=cate.key, tags=[tag1.key, tag2.key])
        b2 = Blog(title="the second emacs blog", context="hello, world",
                  category=cate.key, tags=[tag1.key, tag2.key])
        b3 = Blog(title="the third emacs blog", context="hello, world",
                  category=cate.key, tags=[tag1.key, tag2.key])
        b1.put()
        b2.put()
        b3.put()
开发者ID:hackrole,项目名称:gblog,代码行数:23,代码来源:tests.py


注:本文中的models.Blog.put方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。