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()
Author: honmaple

NO CONTENTS

lin.jiang

风落花语风落天,花落风雨花落田.