Sometimes, we want to serve robot.txt, sitemap.xml static files in Python Flask.
In this article, we’ll look at how to serve robot.txt, sitemap.xml static files in Python Flask.
How to serve robot.txt, sitemap.xml static files in Python Flask?
To serve robot.txt, sitemap.xml static files in Python Flask, we can expose a static folder in our Flask app project’s folder.
For instance, we write
from flask import Flask
app = Flask(__name__, static_folder='static', static_url_path='')
to create a Flask
instance with the static_folder
argument set to the 'static'
folder in our Flask app project’s folder.
Then we can put robots.txt and sitemap.xml inside it.
Conclusion
To serve robot.txt, sitemap.xml static files in Python Flask, we can expose a static folder in our Flask app project’s folder.