Z
Z
Zenoviy Burychko2021-06-20 13:15:52
Django
Zenoviy Burychko, 2021-06-20 13:15:52

Why did the links stop working after adding the Sitemap?

Added a dynamic sitemap to the site. Everything works, sitemap.xml is created and all generated pages are displayed there. But after that, when entering any page of the site, there are errors.

sitemaps.py

class AudiobookSitemap(Sitemap):
    changefreq = "always"
    priority = 0.8
    protocol = 'http'

    def items(self):
        return AudioBook.objects.all()

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

    def location(self, obj):
        return '/audiobook/%s' % (obj.slug)


class BookGenreSitemap(Sitemap):
    changefreq = "always"
    priority = 0.9
    protocol = 'http'

    def items(self):
        return BookGenre.objects.all()

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

    def location(self, obj):
        return '/audiobook_genre/%s' % (obj.slug)


urls.py
app_name = "main"

sitemaps = {
    'audiobook':AudiobookSitemap,
    'audiobook_genre':BookGenreSitemap,
}

urlpatterns = [
    url(r'^$', views.home, name='home'),
    path('sitemap.xml', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'),

    url('search/', SearchResultsView.as_view(), name='search'),

    path("author/<slug:post_slug>/", author, name='author'),
    path("cycle/<slug:post_slug>/", cycle, name='cycle'),

    path("audiobook/<slug:post_slug>/", audiobook, name='audiobook'),
    path("audiobook_genre/<slug:post_slug>/", audiobook_genre, name='audiobook_genre')

]


Well, the error itself when entering the site -
Reverse for 'search' not found. 'search' is not a valid view function or pattern name.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
siarheisiarhei, 2021-06-21
@siarheisiarhei

config_all
urls.py

from django.contrib.sitemaps.views import sitemap
from blog.sitemaps import PostSitemap
from notes.sitemaps import MarginsSitemap
from city_notes.sitemaps import CityMarginsSitemap
from core.sitemaps import CelebrationSitemap, AnimatorSitemap, ServiceSitemap

sitemaps = {
    "blog": PostSitemap,
    "notes": MarginsSitemap,
    "city_notes": CityMarginsSitemap,
    "core.celebration": CelebrationSitemap,
    "core.animator": AnimatorSitemap,
    "core.service": ServiceSitemap,
}

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question