from flask import Flask
from flask_sitemap import Sitemap
app = Flask(__name__)
sitemap = Sitemap(app=app)
@app.route('/<int:some_number>')
def show_number(some_number):
# Do stuff
@sitemap.register_generator
def sitemap():
max_number = 100000
for some_number in range(max_number * -1, max_number * 2):
yield ('show_number', {'some_number': some_number})
$ curl http://localhost:5000/sitemap.xml
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>http://localhost/sitemap1.xml</loc>
</sitemap>
<sitemap>
<loc>http://localhost/sitemap2.xml</loc>
</sitemap>
…
<sitemap>
<loc>http://localhost/sitemap30.xml</loc>
</sitemap>
</sitemapindex>
Debugging middleware caught exception in streamed response at a point where response headers were already sent.
Traceback (most recent call last):
File "/path/to/venv/lib/python3.5/site-packages/flask/app.py", line 1994, in __call__
return self.wsgi_app(environ, start_response)
File "/path/to/venv/lib/python3.5/site-packages/flask/app.py", line 1990, in wsgi_app
ctx.auto_pop(error)
File "/path/to/venv/lib/python3.5/site-packages/flask/ctx.py", line 387, in auto_pop
self.pop(exc)
File "/path/to/venv/lib/python3.5/site-packages/flask/ctx.py", line 379, in pop
'(%r instead of %r)' % (rv, self)
AssertionError: Popped wrong request context. (<RequestContext 'http://localhost/' [GET] of number_shower> instead of <RequestContext 'http://localhost:5000/sitemap1.xml' [HEAD] of number_shower>)
127.0.0.1 - - [30/Dec/2016 10:50:34] "HEAD /sitemap1.xml HTTP/1.1" 200 -