Django Static Sitemap не работает выдает ошибку "Reverse for 'index' not found. 'index' не является допустимой функцией представления или именем шаблона."

Я пытаюсь реализовать Static Sitemap для своего приложения и получаю ошибку "Reverse for 'index' not found. 'index' не является допустимой функцией представления или именем шаблона.", хотя эти представления настроены.

Что может вызвать это? У меня нет проблем с динамическими картами сайта, только со статическими.

Мой views.py


def front_page(request):

    return render(request, 'django_modules_testing_app/front_page.html',
        {
        
        })


def about_us(request):

    return render(request, 'ihgr_app/about_us.html', {
        
        })


def index(request):

    return render(request, 'django_modules_testing_app/index.html',
        {
     
        })

urls.py


from django.urls import path
from . import views
from . import blocks
from django.contrib.sitemaps.views import sitemap

from .sitemaps import DjangoModulesTestingApp

app_name = 'django_modules_testing_app'

sitemaps = {
    'main_app':DjangoModulesTestingApp
}

urlpatterns = [
    path('', views.front_page, name='front_page'),
    path('', views.index, name='index'),
    path('', views.about_us, name='about_us'),

    path('category_details/<slug:slug>/', blocks.category_details, name='category_details'),
    path('search_website/', views.SearchWebsite.as_view(), name='search_website'),

    path('sitemap.xml', sitemap, {'sitemaps': sitemaps},name='django.contrib.sitemaps.views.sitemap')

]


sitemaps.py

from django.contrib.sitemaps import Sitemap
from django.urls import reverse


class StaticSitemap(Sitemap): 
    changefreq = 'weekly'
    priority = 0.8
    protocol = 'http'

    def items(self):
        return ['front_page','index','about_us']  

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



Вы должны указать имя вашего приложения внутри reverse(...) вот так

class StaticSitemap(Sitemap): 
    changefreq = 'weekly'
    priority = 0.8
    protocol = 'http'

    def items(self):
        return ['front_page','index','about_us']  

    def location(self, item):
        return reverse(f"django_modules_testing_app:{item}") 
Вернуться на верх