0
我有我运行生成的RSS提要的文字,然后我在瓶下面的行成为一个Python脚本:如何使用Flask设置RSS mimetype?
return render_template('rss.xml', mimetype='application/rss+xml')
然而,RSS validator说,我的内容仍然被送达text/html
mimetype。怎么来的?
下面是完整的方法:
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def serve(path):
if path == '':
return render_template('about.html', most_recent=request.url_root + post_list[len(post_list) - 1]['route'])
elif path == 'feed':
return render_template('rss.xml', mimetype='application/rss+xml')
elif path in post_paths:
index = post_paths.index(path)
post = post_list[index]
return render_template('posts/' + post['template'],
id=index + 1,
date="{0:02d}/{1:02d}/{2}".format(post['date'].month, post['date'].day,
post['date'].year),
title=post['title'],
most_recent=request.url_root + post_list[len(post_list) - 1]['route']
)
elif path in raws_list:
return render_template('visualizations/' + path)
else:
abort(404)
您应该将该视图分解为多个视图。如果发言,它会删除你很多。 – dirn
我有点同意,我应该。构建像这样的应用程序的可接受方式是什么?一堆'serve_this_content_type()'子方法? –
根据你分享的内容,你应该在''/''处有一个'about' endpoiint,'/ feed''处的'feed'端点,'''/ post////''等等 –
dirn