Le sitemap à l'URL https://www.duhaz.fr/sitemap.xml est vide ou ne contient aucune URL.
cd /Users/duhaz/projets/blog-duhaz
source venv/bin/activate # Si vous avez un venv
python scripts/fix_sitemap_sites.py
Ce script va :
django_sitewww.duhaz.fr# En développement
python manage.py runserver
# En production (selon votre config)
systemctl restart gunicorn
# ou
supervisorctl restart duhaz_blog
Ouvrir dans le navigateur : https://www.duhaz.fr/sitemap.xml
python manage.py migrate
python manage.py shell
Dans le shell Python :
from django.contrib.sites.models import Site
# Créer ou mettre à jour le site
try:
site = Site.objects.get(id=1)
site.domain = 'www.duhaz.fr'
site.name = 'Mr Duhaz'
site.save()
print("✅ Site mis à jour")
except Site.DoesNotExist:
Site.objects.create(id=1, domain='www.duhaz.fr', name='Mr Duhaz')
print("✅ Site créé")
# Vérifier
print(Site.objects.all())
exit()
python manage.py shell
from blog.models import Blog
# Compter les articles publiés
count = Blog.objects.filter(b_publier=True).count()
print(f"Articles publiés : {count}")
# Afficher les premiers
for blog in Blog.objects.filter(b_publier=True)[:5]:
print(f"- {blog.b_titre}")
exit()
# Redémarrer le serveur
systemctl restart gunicorn
# Tester
curl https://www.duhaz.fr/sitemap.xml
Pour identifier précisément le problème :
python scripts/diagnose_sitemap.py
Ce script vérifie :
django.contrib.sites dans INSTALLED_APPSdjango.contrib.sitemaps dans INSTALLED_APPSSITE_ID = 1 dans settings.pymigrate appliquéedjango_sitewww.duhaz.frb_publier=Trueurls.py-- Se connecter à la base de données
python manage.py dbshell
-- Vérifier la table
SELECT * FROM django_site;
-- Doit afficher :
-- id | domain | name
-- 1 | www.duhaz.fr | Mr Duhaz
python manage.py shell
from django.urls import reverse
print(reverse('django.contrib.sitemaps.views.sitemap'))
# Doit afficher : /sitemap.xml
exit()
Solution :
python manage.py migrate
Solution : Ajouter dans duhaz_blog/settings.py :
SITE_ID = 1
Causes possibles :
b_publier=Truewww.duhaz.fr)Solutions :
# Vider le cache
python manage.py shell
>>> from django.core.cache import cache
>>> cache.clear()
>>> exit()
# Redémarrer
systemctl restart gunicorn
Après correction, le sitemap doit contenir :
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.duhaz.fr/blog/</loc>
<lastmod>2025-XX-XX</lastmod>
<changefreq>daily</changefreq>
<priority>0.5</priority>
</url>
<url>
<loc>https://www.duhaz.fr/blog/votre-article</loc>
...
</url>
...
</urlset>
Si le problème persiste :
python scripts/diagnose_sitemap.pyscripts/diagnose_sitemap.py - Diagnostic completscripts/fix_sitemap_sites.py - Correction automatiquescripts/generate_sitemap_preview.py - Génération testLa cause la plus fréquente est django.contrib.sites non configuré.
Exécutez python scripts/fix_sitemap_sites.py pour corriger automatiquement !