本文整理汇总了Python中model.Page.slug方法的典型用法代码示例。如果您正苦于以下问题:Python Page.slug方法的具体用法?Python Page.slug怎么用?Python Page.slug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Page
的用法示例。
在下文中一共展示了Page.slug方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from model import Page [as 别名]
# 或者: from model.Page import slug [as 别名]
def post(self):
name = self.get_argument("name", None)
slug = self.get_argument("slug", None)
content = self.get_argument("content", "")
template = self.get_argument("template", "staticpage.html")
page = Page()
page.name = name
page.slug = slug
page.content = content
page.template = template
try:
page.validate()
page.save()
self.flash(u"栏目%s添加成功" % name)
self.redirect("/admin/pages")
return
except Exception, ex:
self.flash(str(ex))
示例2: save
# 需要导入模块: from model import Page [as 别名]
# 或者: from model.Page import slug [as 别名]
def save():
try:
add = False
title = request.form['title']
content = request.form['content']
slug = request.form['slug']
if 'id' in request.form:
page = Page.query.get(request.form['id'])
cache.delete('view-page-%s' % slug) #Remove this page from cache for update in next view
else:
add = True
page = Page()
page.date_created = datetime.today()
page.title = title
page.content = content
page.slug = slug
page.date_updated = datetime.today()
if add:
db.session.add(page)
db.session.commit()
data = {}
data['message'] = "Página salva com sucesso! <a href='%s'>Visualizar</a>" % url_for('pages.view', slug=slug)
data['id'] = page.id
return jsonify(data)
except IntegrityError as e:
db.session.rollback()
data = {}
data['message'] = "O Slug informado ja existe. Altere e tente novamente."
return jsonify(data)
except:
db.session.rollback()
print "Unexpected error:", sys.exc_info()[0]
raise