0

I'm using the Django Sitemap Framework.

You can see my sitemap here:

https://dealmazing.com/sitemap.xml

It seems to be picking up my blog at /blog

but not my actual blog posts. it looks like it is recording the actual posts over and over again as dealmazing.com/blog but without the real URL

This is my sitemaps.xml file

from django.contrib import sitemaps
from django.contrib.sitemaps import Sitemap
from django.urls import reverse
from deals.models import Deal, Category, Retailer
from blog.models import Post, BlogCategory

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

    def items(self):
        return ['about', 'contact', 'disclosure', 'terms', 'privacy', 'deals:deals', 'blog:blog']

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


class BlogSitemap(Sitemap):
    changfreq = "daily"
    priority = 1.0
    location ='/blog'

    def items(self):
        return Post.objects.filter(status='Published')

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

class BlogCategorySitemap(Sitemap):
    changfreq = "daily"
    priority = 1.0

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

class DealCategorySitemap(Sitemap):
    changfreq = "daily"
    priority = 1.0

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

class RetailerSitemap(Sitemap):
    changfreq = "daily"
    priority = 1.0

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


class DealSitemap(Sitemap):
    changfreq = "daily"
    priority = 1.0

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

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

and in my urls file

sitemaps = {
    'static': StaticViewSitemap,
    'blog': BlogSitemap,
    'blog-category': BlogCategorySitemap,
    'deals': DealSitemap,
    'deals-category': DealCategorySitemap,
    'retailers': RetailerSitemap
}

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

I can't quite determine why it is not posting the full URL

John Rogerson
  • 1,153
  • 2
  • 19
  • 51
  • Because of `location ='/blog'`. Consider changing it to a method as you did with `StaticViewSitemap`. – Selcuk May 11 '18 at 02:11
  • 1
    ok yep--you're right, just removed that and set the get_absolute_url on the model, and works perfect...thanks! – John Rogerson May 11 '18 at 02:26

0 Answers0