flask中生成atom


参考资料1 参考资料2

 1下面是具体代码
 2# from urlparse import urljoin #python2
 3from urllib.parse import urljoin
 4from flask import request
 5from werkzeug.contrib.atom import AtomFeed
 6
 7
 8def make_external(url):
 9    return urljoin(request.url_root, url)
10
11
12@site.route('/atom.xml')
13def feed():
14    feed = AtomFeed('Recent Articles',
15                    feed_url=request.url,
16                    url=request.url_root,
17                    subtitle='I like solitude, yearning for freedom')
18    articles = Articles.query.limit(15).all()
19    for article in articles:
20        feed.add(
21            article.title,
22            article.content,
23            content_type='html',
24            author=article.author,
25            url=make_external(url_for('blog.view', id=article.id)),
26            updated=article.publish,
27            published=article.publish)
28    return feed.get_response()
作者: honmaple
链接: https://honmaple.me/articles/2016/05/flask中生成atom.html
版权: CC BY-NC-SA 4.0 知识共享署名-非商业性使用-相同方式共享4.0国际许可协议
wechat
alipay

加载评论