下面是具体代码
# 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()
NO CONTENTS