本文整理汇总了Python中model.Article.create方法的典型用法代码示例。如果您正苦于以下问题:Python Article.create方法的具体用法?Python Article.create怎么用?Python Article.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Article
的用法示例。
在下文中一共展示了Article.create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put_article
# 需要导入模块: from model import Article [as 别名]
# 或者: from model.Article import create [as 别名]
def put_article():
'''
Add new article for a user.
'''
username = request.headers.get('x-koala-username')
apikey = request.headers.get('x-koala-key')
user = locate_user(username, apikey)
reqjson = request.get_json()
result = validators.url(reqjson['url'])
if not result:
# try again but with http://
result = validators.url('http://' + reqjson['url'])
if not result:
logging.info("Bad URL: %s" % reqjson['url'])
abort(400)
else:
reqjson['url'] = 'http://' + reqjson['url']
title = reqjson.get('title', reqjson['url'])
url = reqjson['url']
date = str(datetime.now())
read = False
favorite = False
owner = user.id
article = Article.create(title=title, url=url, date=date, read=read, favorite=favorite, owner=owner)
return jsonify({'id': article.id}), 201
示例2: post
# 需要导入模块: from model import Article [as 别名]
# 或者: from model.Article import create [as 别名]
def post(self):
title = self.get_argument('title')
content_md = self.get_argument('content')
pattern = r'\[[^\[\]]+\]'
labels = re.findall(pattern, self.get_argument('labels'))
content_html = markdown.markdown(content_md, ['codehilite'])
try:
article_id = Article.create(self.db, title, content_md, content_html)
for label in labels:
detail = label[1:-1].strip()
Label.create(self.db, article_id, detail)
self.redirect('/', permanent=True)
except:
error = "The post data invalid"
self.render('error.html', error=error, home_title=options.home_title)