flask中生成atom


参考资料1 参考资料2

下面是具体代码
# from urlparse import urljoin #python2
from urllib.parse import urljoin
from flask import request
from werkzeug.contrib.atom import AtomFeed


def make_external(url):
    return urljoin(request.url_root, url)


@site.route('/atom.xml')
def feed():
    feed = AtomFeed('Recent Articles',
                    feed_url=request.url,
                    url=request.url_root,
                    subtitle='I like solitude, yearning for freedom')
    articles = Articles.query.limit(15).all()
    for article in articles:
        feed.add(
            article.title,
            article.content,
            content_type='html',
            author=article.author,
            url=make_external(url_for('blog.view', id=article.id)),
            updated=article.publish,
            published=article.publish)
    return feed.get_response()
作者: honmaple
链接: https://honmaple.me/articles/2016/05/flask中生成atom.html
版权: 知识共享署名-非商业性使用-相同方式共享4.0国际许可协议
wechat