Fixed #34688 -- Removed contrib.sitemaps.ping_google() and ping_google management command.

Thanks Joachim Jablon for the report.

Google has deprecated the sitemap ping endpoint, and will be removing
it in 6 months ~January 2024.
This commit is contained in:
Andrew Northall 2023-07-02 21:48:56 +01:00 committed by Mariusz Felisiak
parent 2584783f46
commit 6d427288e4
13 changed files with 12 additions and 259 deletions

View file

@ -588,78 +588,3 @@ generate a Google News compatible sitemap:
</urlset>
.. _`Google news sitemaps`: https://support.google.com/news/publisher-center/answer/9606710
Pinging Google
==============
You may want to "ping" Google when your sitemap changes, to let it know to
reindex your site. The sitemaps framework provides a function to do just
that: :func:`django.contrib.sitemaps.ping_google()`.
.. function:: ping_google(sitemap_url=None, ping_url=PING_URL, sitemap_uses_https=True)
``ping_google`` takes these optional arguments:
* ``sitemap_url`` - The absolute path to your site's sitemap (e.g.,
:file:`'/sitemap.xml'`).
If this argument isn't provided, ``ping_google`` will perform a reverse
lookup in your URLconf, for URLs named
``'django.contrib.sitemaps.views.index'`` and then
``'django.contrib.sitemaps.views.sitemap'`` (without further arguments) to
automatically determine the sitemap URL.
* ``ping_url`` - Defaults to Google's Ping Tool:
https://www.google.com/webmasters/tools/ping.
* ``sitemap_uses_https`` - Set to ``False`` if your site uses ``http``
rather than ``https``.
:func:`ping_google` raises the exception
``django.contrib.sitemaps.SitemapNotFound`` if it cannot determine your
sitemap URL.
.. admonition:: Register with Google first!
The :func:`ping_google` command only works if you have registered your
site with `Google Search Console`_.
.. _`Google Search Console`: https://search.google.com/search-console/welcome
One useful way to call :func:`ping_google` is from a model's ``save()``
method::
from django.contrib.sitemaps import ping_google
class Entry(models.Model):
# ...
def save(self, force_insert=False, force_update=False):
super().save(force_insert, force_update)
try:
ping_google()
except Exception:
# Bare 'except' because we could get a variety
# of HTTP-related exceptions.
pass
A more efficient solution, however, would be to call :func:`ping_google` from a
cron script, or some other scheduled task. The function makes an HTTP request
to Google's servers, so you may not want to introduce that network overhead
each time you call ``save()``.
Pinging Google via ``manage.py``
--------------------------------
.. django-admin:: ping_google [sitemap_url]
Once the sitemaps application is added to your project, you may also
ping Google using the ``ping_google`` management command:
.. code-block:: shell
python manage.py ping_google [/sitemap.xml]
.. django-admin-option:: --sitemap-uses-http
Use this option if your sitemap uses ``http`` rather than ``https``.

View file

@ -1759,18 +1759,6 @@ documentation.
Can be run as a cron job or directly to clean out expired sessions.
``django.contrib.sitemaps``
---------------------------
``ping_google``
~~~~~~~~~~~~~~~
This command is only available if the :doc:`Sitemaps framework
</ref/contrib/sitemaps>` (``django.contrib.sitemaps``) is installed.
Please refer to its :djadmin:`description <ping_google>` in the Sitemaps
documentation.
``django.contrib.staticfiles``
------------------------------