NoReverseMatch at /sitemap.xml

194 views
Skip to first unread message

Yash Garg

unread,
Feb 19, 2020, 11:43:07 AM2/19/20
to Django users
When i'm loading sitemap.xml for my site i'm getting this error

Reverse for 'blog-detail' with arguments '('This is my title slug', '2020', '2', '19')' not found. 1 pattern(s) tried: ['blog\\/(?P<year>[0-9]+)\\/(?P<month>[0-9]+)\\/(?P<day>[0-9]+)\\/(?P<slug>[-a-zA-Z0-9_]+)$']

sitemap.py

class BlogSitemap(Sitemap):
priority = 0.5
changefreq = 'daily'

def items(self):
return Blog.objects.filter(status=1)

def location(self, item):
return reverse('blog-detail', args = (item.slug, str(item.blog_published_at.year), str(item.blog_published_at.month), str(item.blog_published_at.day)))

Models.py
class Blog(models.Model):

STATUS = (
(0,"Draft"),
(1,"Publish")
)

blog_title = models.CharField(_("Blog Title For Slug"), validators=[MinLengthValidator(8)], max_length=120, blank=False,null=False)
title = models.CharField(_("Blog Title"), validators=[MinLengthValidator(8)], max_length=120, blank=True,null=False)
slug = models.SlugField(_("Slug"), max_length=200, unique = True, blank = True)
meta_tag = models.TextField(_("Blog Meta tags"), null = False, blank= True)
banner_text = models.CharField(_("Top Banner Text Overlay"), max_length = 50, null = False)
banner_image = models.FileField(_("Banner Image"), blank=True)
blog_abstract = models.TextField(_("Blog Abstract"), max_length= 500, blank = False, null = False)
blog_published_at = models.DateField(_("Blog published date") , blank = False, default = timezone.now)
blog_image = models.FileField(_("Blog Image"), blank=True)
def __str__(self):
return self.title

class Meta:
ordering = ['-blog_published_at']
db_table = '"public_blog"'

def get_absolute_url(self):
return reverse('blog-detail', args=(self.slug, self.blog_published_at.year, self.blog_published_at.month, self.blog_published_at.day))

def save(self):
super(Blog, self).save()
self.slug = slugify(self.blog_title)
super(Blog, self).save()
urls.py

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

How can i resolve this issue?

Thank You

Yash Garg

unread,
Feb 22, 2020, 11:00:42 AM2/22/20
to Django users
Please help me to resolve this issue.

Peter of the Norse

unread,
Mar 4, 2020, 10:32:43 PM3/4/20
to 'Dick in Texas' via Django users
You are using positional arguments when you should be using named args.  Change the line to

return reverse('blog-detail', kwargs = {‘slug’:item.slug, ‘year’:str(item.blog_published_at.year), ‘month’:str(item.blog_published_at.month), ‘day’:str(item.blog_published_at.day)})


-- 
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7afdb4f4-ac77-4495-b558-9042fd70cf29%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages