Flask extension for generating XML sitemaps
Project description
Flask Sitemapper
Flask Sitemapper is a Python 3 package that generates XML sitemaps for Flask applications. This allows you to create fully functional sitemaps and sitemap indexes for your Flask projects with minimal code.
You can install the latest version of Flask Sitemapper with pip:
pip install flask-sitemapper
For documentation (including for contributors), see the wiki.
Features
- Easily generate and serve XML sitemaps and sitemap indexes for your Flask apps
- Include URLs in your sitemaps by adding a decorator to their route/view functions
- Serve your sitemap on any URL you choose
- Include lastmod, changefreq, and priority information in your sitemaps
- Specify whether to use HTTP or HTTPS for the URLs in your sitemaps
- Compress your sitemaps using GZIP
- Create multiple sitemaps and sitemap indexes for the same app
- Supports apps using Flask blueprints
- Supports apps serving multiple domains
- Supports dynamic routes
- Works with many different app structures
Sitemaps
Sitemaps are an easy way for webmasters to inform search engines about pages on their sites that are available for crawling. In its simplest form, a Sitemap is an XML file that lists URLs for a site along with additional metadata about each URL (when it was last updated, how often it usually changes, and how important it is, relative to other URLs in the site) so that search engines can more intelligently crawl the site. — sitemaps.org
For more information about sitemaps and the sitemap protocol, visit sitemaps.org
Basic Code Example
import flask
from flask_sitemapper import Sitemapper
sitemapper = Sitemapper()
app = flask.Flask(__name__)
sitemapper.init_app(app)
@sitemapper.include(lastmod="2022-02-08")
@app.route("/")
def home():
return flask.render_template("home.html")
@sitemapper.include(lastmod="2022-03-19")
@app.route("/about")
def about():
return flask.render_template("about.html")
@app.route("/sitemap.xml")
def sitemap():
return sitemapper.generate()
app.run()
With the above code running on localhost, http://localhost/sitemap.xml
will serve the following XML sitemap:
<?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://localhost/</loc>
<lastmod>2022-02-08</lastmod>
</url>
<url>
<loc>https://localhost/about</loc>
<lastmod>2022-03-19</lastmod>
</url>
</urlset>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file flask_sitemapper-1.8.0.tar.gz
.
File metadata
- Download URL: flask_sitemapper-1.8.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e065f58db2ca089226fb8a1065863eef3cda9a0f24683904e5979caccacd8d5f |
|
MD5 | 0ce6e2e05e513e7490bd072d71808358 |
|
BLAKE2b-256 | 41fc283d80351f9b9274093be7ed2a9a10d1791db7c3d7c9f39eeb3370de89fa |
File details
Details for the file flask_sitemapper-1.8.0-py3-none-any.whl
.
File metadata
- Download URL: flask_sitemapper-1.8.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 921eeecd6855b99990d4663ff4e9e31fe9dac0551a465f8b0811444ada18d6da |
|
MD5 | 5f415eb1ecce24841d4fa9f4be5c3bed |
|
BLAKE2b-256 | 657597c7a12ce19cd21b8d7f2e4a3e9185763e00546c94edd648f1fa5df7fd53 |