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