0

I'm trying to add sitemaps in my application, but when i add a url that has slug, it throws me an error in http://127.0.0.1:8000/sitemap.xml

Reverse for 'view-Question' with no arguments not found. 1 pattern(s) tried: ['questions/(?P[-a-zA-Z0-9_]+)/\Z']

i follow this Tutorial

my urls:

sitemaps = {
'static': StaticViewSitemap,
}  

path('', views.Home, name='Home'),
path('login', views.login, name='login'),
path('register/', views.register, name='register'),
path('Terms', views.rules, name='Rules'),
path('questions/<slug:slug>/', views.viewQuestion, name='view-Question'),
path('feedback/', views.PostFeedBack.as_view(), name='FeedBack'),
path('sitemap.xml', sitemap, {'sitemaps': sitemaps},
     name='django.contrib.sitemaps.views.sitemap'),

my sitemaps.py file:

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

class StaticViewSitemap(sitemaps.Sitemap):
    priority = 0.5
    changefreq = 'daily'

    def items(self):
        return ['Home', 'login', 'register', 'Rules', 'FeedBack', 'view-Question']

    def location(self, item):
        return reverse(item)
Sunderam Dubey
  • 1
  • 11
  • 20
  • 40

1 Answers1

0

My approach of calling reverse(item) isn't going to work for URL patterns that have arguments. I can't simply call:

 reverse(item)

I need a primary key e.g.

reverse('view-Question', args=[item])

That is how i solve my problem.