Discussion on: How to add sitemap.xml to your Django Blog and make it work on Heroku (SEO)

dumdum profile image
dum dum

Hi! I got problem with my sitemap.xml url.
In local localhost:8000/sitemap.xml works.
But in production domain.com/sitemap.xml got error http 500.
I'm using django3.1, python 3.8.5, heroku hobby basic.

Once I successfully submitted my sitemap on google search console.
But suddenly after few days when I tried to resubmit the sitemap, I got error "couldn't fetch".
When I checked heroku logs --tail, and try to visit domain.com/sitemap.xml, I got http error 500.
Site matching query does not exist.

I've set auto migrate on procfile, so automatically heroku will migrate for me everytime I deployed my app.
I've tried to manually migrate on heroku cli, then restart dyno using heroku restart. But error http 500 still exist.

I researched on the internet, tried many solutions, but didn't work.
Please help. Thanks

radualexandrub profile image
Radu-Alexandru B Author

Do you have any "Sites" model when you are accessing the admin panel from domain.com/admin (from deployment)? If not, you should open your terminal and call (after you added sitemap configurations as shown in this post):

> heroku run bash
$ python manage.py migrate
> heroku restart

This was my solution to fixing the problem that you have. However, if you do have a "Sites" model in your admin panel, try accessing it and change the first entry from example.com to yourdomain.com. Furthermore, check that you have the corresponding settings in YourDjangoApp/settings.py:

SECRET_KEY = os.environ.get('SECRET_KEY')
DEBUG = (os.environ.get("DEBUG_VALUE") == "True")
ALLOWED_HOSTS = ["yourdomain.com",

Also, recheck your MainApp/urls.py as shown in this post's mini-tutorial.
Hope you will find a solution to your problem... Good luck!

dumdum profile image
dum dum

I've checked everything, I did what you told me.
Still got error 500 in production. :(

Argh.. I spent months finding this solutions.
Also, I have another problem about environment variables in Windows.
I put my secret key in my environment variables, I set my settings.py, then I ran py manage.py runserver.

I got error "django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty."

I don't know what to do. :(