By default, django-robots automatically adds a Sitemap statement to your robots.txt by reverse matching the URL of the installed Django Sitemap contrib app.
Configuration Options
- Disable automatic sitemap inclusion: Set
ROBOTS_USE_SITEMAP = False. - Specify custom sitemap URLs: Provide a list of URLs via
ROBOTS_SITEMAP_URLS. - Handle decorated or custom sitemap views: If your sitemap view uses a decorator (like
cache_page) or is a custom view (e.g., Wagtail), the automatic discovery via dotted path might fail. To fix this, name your sitemap view in urls.py and provide that name to ROBOTS_SITEMAP_VIEW_NAME.
Example for decorated sitemaps:
In urls.py:
re_path(r'^sitemap\.xml$', cache_page(60)(sitemap_view, {'sitemaps': [...]}), name='cached-sitemap')
In settings.py:
ROBOTS_SITEMAP_VIEW_NAME = 'cached-sitemap'
ROBOTS_USE_SITEMAP = False
ROBOTS_SITEMAP_URLS = ['http://www.example.com/sitemap.xml']
ROBOTS_SITEMAP_VIEW_NAME = 'cached-sitemap'