[Answered ]-Django Site_ID's and Sitemaps

1๐Ÿ‘

โœ…

I forgot to remove the square brackets in python manage.py ping_google [/sitemap.xml] which causes the command to not work.

1๐Ÿ‘

You can try with requests, which is much easier to understand:

PING_URL = "http://www.google.com/webmasters/tools/ping"

def ping_google(sitemap_url=None, ping_url=PING_URL):
    if not sitemap_url:
        raise Exception('sitemap url must be given')

    current_site = Site.objects.get_current()
    url = "http://%s%s" % (current_site.domain, sitemap_url)
    requests.get(
        ping_url, params={'sitemap': url}   
    )

the original ping_google function lives here:

...\site-packages\django\contrib\sitemaps\__init__.py

๐Ÿ‘คdoniyor

0๐Ÿ‘

If you want to run the command directly from the view:

from django.core.management import call_command

def daily_crons_view(request):
    # Ping Google
    return call_command('ping_google [/sitemap.xml]')
๐Ÿ‘คYousef Alm

Leave a comment