Skip to content

Commit

Permalink
python/django: Add instructions about sitemaps for public sites
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Dec 11, 2023
1 parent 63ad97a commit f58a4d7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django.contrib.sitemaps",
]

MIDDLEWARE = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from django.contrib import admin
from django.contrib.sitemaps.views import sitemap
from django.urls import path

sitemaps = {}

urlpatterns = [
path("admin/", admin.site.urls),
path("sitemap.xml", sitemap, {"sitemaps": sitemaps}, name="django.contrib.sitemaps.views.sitemap"),
]
10 changes: 10 additions & 0 deletions docs/python/django.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ URLs
- Use hyphens as separators in `named URL patterns <https://docs.djangoproject.com/en/4.2/topics/http/urls/#naming-url-patterns>`__.
- Use `Django REST Framework <https://www.django-rest-framework.org>`__, instead of writing REST endpoints by hand. (See :doc:`preferences`.)

Sitemap
~~~~~~~

Public sites should serve a ``sitemap.xml`` file.

- Do not set ``changefreq`` or ``priority``. (`"Google ignores priority and changefreq values." <https://developers.google.com/search/docs/crawling-indexing/sitemaps/build-sitemap>`__)
- Do not use ``django.contrib.sitemaps.ping_google()``. (`"Sitemaps ping endpoint is going away." <https://developers.google.com/search/blog/2023/06/sitemaps-lastmod-ping>`__)

.. _django-models:

Models
Expand Down Expand Up @@ -174,6 +182,8 @@ Using the template
Remove, unless using ``django.contrib.admin``, ``django.contrib.auth``, ``django.contrib.messages`` or anonymous sessions (check for occurrences of ``session``).
`django.contrib.staticfiles <https://docs.djangoproject.com/en/4.2/ref/contrib/staticfiles/>`__ (`how-to <https://docs.djangoproject.com/en/4.2/howto/static-files/>`__)
Remove, unless the project contains static files.
`django.contrib.sitemaps <https://docs.djangoproject.com/en/4.2/ref/contrib/sitemaps/>`__
Remove, if the application is private. (Added by the Cookiecutter template.)

Then, make any corresponding changes to ``urls.py``, and ``MIDDLEWARE``, ``TEMPLATES``, ``STATIC_URL`` and ``AUTH_PASSWORD_VALIDATORS`` in ``settings.py``.
`DATABASES <https://docs.djangoproject.com/en/4.2/ref/settings/#std:setting-DATABASES>`__
Expand Down

0 comments on commit f58a4d7

Please sign in to comment.