使用Flask,如何将robots.txt和sitemap.xml作为静态文件提供?[重复]
这个问题已经在这里有了答案 :
Flask中的静态文件-
robot.txt,sitemap.xml(mod_wsgi) (10个答案)
5年前关闭。
我已经在安静的地方阅读过一些内容,这些内容应该将静态文件提供给服务器,例如,关于SO问题的几个答案。但是我使用的是OpenShift
PaaS,无法弄清楚在那里如何修改.htaccess文件。
我碰到了这段代码,它通过模板为站点地图提供服务。我在应用程序中同时针对站点地图和robots.txt做到了这一点,就像这样-
@app.route("/sitemap.xml")
def sitemap_xml():
response= make_response(render_template("sitemap.xml"))
response.headers['Content-Type'] = 'application/xml'
return response
@app.route("/robots.txt")
def robots_txt():
return render_template("robots.txt")
这有什么危害吗,或者我的方法还可以吗?