Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django sitemap change base url

Tags:

django

sitemap

I'm using https://docs.djangoproject.com/en/dev/ref/contrib/sitemaps/?from=olddocs .

I have a sitemap generated from api.mydomain.me for the domain: mydomain.com.

Can I, with django, specify a base url ?

Now with location() method return:

api.mydomain.me/page/3123 instead of mydomain.com/page/3123

Is this possible? Thanks.

like image 377
beddamadre Avatar asked Apr 30 '12 22:04

beddamadre


2 Answers

Solved, I redefined my own get_urls. It works:

class MySitemap(Sitemap):
    changefreq = "never"
    priority = 0.5
    location = ""

    def get_urls(self, site=None, **kwargs):
        site = Site(domain='mydomain.com', name='mydomain.com')
        return super(MySitemap, self).get_urls(site=site, **kwargs)

    def items(self):
        return MyObj.objects.all().order_by('pk')[:1000]

    def lastmod(self, obj):
        return obj.timestamp
like image 189
beddamadre Avatar answered Oct 18 '22 03:10

beddamadre


I didn't know how to use Site in my code by using previous answers so I used below code:

class Site:
    domain = 'my_site.com'


class MySitemap(Sitemap):
    def get_urls(self, site=None, **kwargs):
        site = Site()
        return super(MySitemap, self).get_urls(site=site, **kwargs)
like image 20
mastisa Avatar answered Oct 18 '22 05:10

mastisa