# NoReverseMatch at /sitemap.xml

**URL:** <https://forum.djangoproject.com/t/noreversematch-at-sitemap-xml/17300>\
**Category:** Mystery Errors\
**Created:** [November 28, 2022, 3:02am UTC](https://forum.djangoproject.com/t/noreversematch-at-sitemap-xml/17300 "2022-11-28T03:02:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shawnngtq](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/shawnngtq/32/5834_2.png) [@shawnngtq](https://forum.djangoproject.com/u/shawnngtq)\
**Post date:** [November 28, 2022, 3:02am UTC](https://forum.djangoproject.com/t/noreversematch-at-sitemap-xml/17300/1 "2022-11-28T03:02:22Z")

</div>

## Context

Recently add sitemap index as I have \>50,000 urls.

Following the documentation: [The sitemap framework | Django documentation | Django](https://docs.djangoproject.com/en/4.1/ref/contrib/sitemaps/#creating-a-sitemap-index)

### NoReverseMatch at /sitemap.xml

[https://example.com/sitemap.xml](https://example.com/sitemap.xml) return 500 error with this error message

```auto
Reverse for 'django.contrib.sitemaps.views.sitemap' not found. 'django.contrib.sitemaps.views.sitemap' is not a valid view function or pattern name.

```

But these sections work

- [https://example.com/sitemap-static.xml](https://example.com/sitemap-static.xml)
- [https://example.com/sitemap-something.xml](https://example.com/sitemap-something.xml)
- [https://example.com/sitemap-something.xml?p=2](https://example.com/sitemap-something.xml?p=2)

## Code

```python
# sitemaps.py
from django.contrib.sitemaps import Sitemap
from django.shortcuts import reverse
from something.models import Something

class StaticViewSitemap(Sitemap):
    def items(self):
        return ["home:index", "home:privacy", "home:terms"]

    def location(self, item):
        return reverse(item)

class SomethingSitemap(Sitemap):
    limit = 5000

    def items(self):
        return Something.objects.filter(is_hidden=False).order_by("-pk")

    def lastmod(self, obj):
        return obj.updated_at

```

```auto
# urls.py
sitemaps = {
    "static": StaticViewSitemap,
    "something": SomethingSitemap,
}

urlpatterns = [
   ...
    path(
        "sitemap.xml",
        views.index,
        {"sitemaps": sitemaps},
        name="django.contrib.sitemaps.views.index",
    ),
    path(
        "sitemap-<section>.xml",
        views.sitemap,
        {"sitemaps": sitemaps},
        name="django.contrib.sitemaps.views.sitemap",
    ),
]

```

## Attempts

I tried `sitemap_url_name` no effect.

I tried adding `location` to `SomethingSitemap`, no effect.

---

<div class="post-metadata">

**Author:** ![shawnngtq](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/shawnngtq/32/5834_2.png) [@shawnngtq](https://forum.djangoproject.com/u/shawnngtq)\
**Post date:** [November 28, 2022, 7:02am UTC](https://forum.djangoproject.com/t/noreversematch-at-sitemap-xml/17300/2 "2022-11-28T07:02:30Z")

</div>

Found the root cause.

Solution is to move the sitemap to `yourproject.urls.py` from `yourapp.urls.py`

This is mentioned in the documentation: [The sitemap framework | Django documentation | Django](https://docs.djangoproject.com/en/4.1/ref/contrib/sitemaps/#initialization)

Specifically:

```auto
The name of the sitemap file is not important, but the location is. Search engines will only index links in your sitemap for the current URL level and below. For instance, if sitemap.xml lives in your root directory, it may reference any URL in your site. However, if your sitemap lives at /content/sitemap.xml, it may only reference URLs that begin with /content/.

```
