當前位置: 首頁>>代碼示例>>Python>>正文


Python Category.slug方法代碼示例

本文整理匯總了Python中models.Category.slug方法的典型用法代碼示例。如果您正苦於以下問題:Python Category.slug方法的具體用法?Python Category.slug怎麽用?Python Category.slug使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Category的用法示例。


在下文中一共展示了Category.slug方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: post

# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import slug [as 別名]
    def post(self):
        json = {}
        if not self.current_user:
            json = {
                'error': 1,
                'msg': self._('Access denied')
            }
            self.write(json)
            return

        title = self.get_argument('title', None)
        slug = self.get_argument('slug', None)
        description = self.get_argument('description', '')
        # valid arguments
        if not title:
            json = {
                'error': 1,
                'msg': self._('Title field can not be empty')
            }
            self.write(json)
            return
        if not slug:
            json = {
                'error': 1,
                'msg': self._('Slug field can not be empty')
            }
            self.write(json)
            return
        elif self.get_category_by_slug(slug):
            json = {
                'error': 1,
                'msg': self._('Slug already exists')
            }
            self.write(json)
            return
        # create category
        category = Category()
        category.title = title
        category.slug = slug
        category.description = description
        self.db.add(category)
        self.db.commit()
        # delete cache
        keys = ['CategoryList', 'SystemStatus']
        self.cache.delete_multi(keys)

        json = {
            'error': 0,
            'msg': self._('Successfully created'),
            'category': {
                'id': category.id,
                'title': category.title,
                'slug': category.slug,
                'description': category.description,
                'permalink': category.permalink,
                'post_count': category.post_count
            }
        }
        self.write(json)
開發者ID:messense,項目名稱:YaBlog,代碼行數:61,代碼來源:api.py

示例2: add_category

# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import slug [as 別名]
def add_category(request):
    if request.method == "POST":
        category = Category()
        category.name = request.POST["name"]
        category.slug = request.POST["slug"]
        category.put()
        return HttpResponseRedirect("/category/add")
    return render_to_response("add_category.html", context_instance=RequestContext(request))
開發者ID:ytrstu,項目名稱:niubi,代碼行數:10,代碼來源:views.py

示例3: add_category

# 需要導入模塊: from models import Category [as 別名]
# 或者: from models.Category import slug [as 別名]
def add_category(request):
    if request.method == 'POST':
        category = Category()
        category.name = request.POST['name']
        category.slug = request.POST['slug']
        category.put();   
        return HttpResponseRedirect('/category/add')  
    return render_to_response('add_category.html', context_instance=RequestContext(request))
開發者ID:lvbeck,項目名稱:niubi,代碼行數:10,代碼來源:views.py


注:本文中的models.Category.slug方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。