本文整理匯總了Python中model.Page.date_created方法的典型用法代碼示例。如果您正苦於以下問題:Python Page.date_created方法的具體用法?Python Page.date_created怎麽用?Python Page.date_created使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類model.Page
的用法示例。
在下文中一共展示了Page.date_created方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: save
# 需要導入模塊: from model import Page [as 別名]
# 或者: from model.Page import date_created [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