Given you want to establish http://example.com/sitemap.xml as your sitemap URL do that.
Add this line to init.py to register URL pattern http://example.com/sitemap.xml as route sitemap
config.add_route('sitemap', '/sitemap.xml')
register view code for route sitemap
and render response with your custom jinja2 template sitemap.jinja2
. The file extension `jinja2' will trigger usage of jinja2 renderer.
@view_config(route_name='sitemap', renderer='static/sitemap.jinja2')
def sitemap(request):
ingredients = [ ingredient.name for ingredient in Cosmeceutical.get_all() ]
products = [ product.name for product in Product.get_all() ]
return dict(ingredients=ingredients, products=products)
This will fix your errors resulting from trying to name your templates like URLs. But that mixed up renderer conventions shown below.
- *.pt triggers Chameleon renderer
- *.jinja2 triggers Jinja2 renderer
- *.mako triggers Mako renderer
- *.xml triggers XML renderer (that raised your first error)
Now it is still up to you to create XML based on sitemaps protocol. But your code looks promising. You pass your resource tree to the XML template. Every resource usually has access to their properties like URL or last_changed stuff.