flask seo code example
Example: flask seo
@app.route('/sitemap.xml', methods=['GET'])
def sitemap():
try:
"""Generate sitemap.xml. Makes a list of urls and date modified."""
pages=[]
ten_days_ago=(datetime.now() - timedelta(days=7)).date().isoformat()
for rule in app.url_map.iter_rules():
if "GET" in rule.methods and len(rule.arguments)==0:
pages.append(
["http://pythonprogramming.net"+str(rule.rule),ten_days_ago]
)
sitemap_xml = render_template('sitemap_template.xml', pages=pages)
response= make_response(sitemap_xml)
response.headers["Content-Type"] = "application/xml"
return response
except Exception as e:
return(str(e))