Saturday, February 22, 2020

Re: NoReverseMatch at /sitemap.xml

Please help me to resolve this issue.

On Wednesday, February 19, 2020 at 10:13:07 PM UTC+5:30, Yash Garg wrote:
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

--
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+unsubscribe@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.

No comments:

Post a Comment