What is the best method of creating sitemaps?

Hello. I would like to know how best to create sitemap for the django project. Especially if I have 4 apps: App1, App2, App3 … and so on. And every has many models. Documentation and many turotials show only creation of sitemap for one App with one or two models, so I’m confused how to create sitemap for big project. Every single sitemap for every App? And what about packege Django-sitemap. Is it worth using? What is better opt for SEO? Thanks in advance

Have you tried using the existing sitemap feature?

What makes you think that using it would be any different for a large project than for a small project?

“Large” and “small” are also extremely relative terms. There was a discussion here about a month ago where someone was trying to generate a sitemap for more than 500,000 entries.

Note that in the docs at The sitemap framework | Django documentation | Django

You should create an index file if one of your sitemaps has more than 50,000 URLs. In this case, Django will automatically paginate the sitemap, and the index will reflect that.

So how many URLs are you talking about?

1 Like

Thanks for response! I mean should I create one general sitemap in urls? . Suppose I have such project:

app Diseases
models:
MedBranch, Theme, Subtheme, Article
app Drugs
models:
MainCategory, CategoryDrug, Drug, DrugArticle
app Nutrition
models:
Category, ThemeNutrition, Article

So, I created sitemap in urls.py:

medbranch_sitemap = {
    'queryset': MedBranch.filter(is_published=True).order_by('-updated_at'),
}

theme_sitemap = {
    'queryset': Theme.filter(is_published=True).order_by('-updated_at'),
}

article_sitemap = {
    'queryset': Article.filter(is_published=True).order_by('-updated_at'),
}

maincategory_sitemap = {
    'queryset': MainCategory.filter(is_published=True).order_by('-updated_at'),
}

categorydrug_sitemap = {
    'queryset': CategoryDrug.filter(is_published=True).order_by('-updated_at'),
}

drug_sitemap = {
    'queryset': Drug.filter(is_published=True).order_by('-updated_at'),
}
drugarticle_sitemap = {
    'queryset': DrugArticle.filter(is_published=True).order_by('-updated_at'),
} 
///////// and so on

sitemaps = {
    'medbranches': GenericSitemap(medbranch_sitemap, priority=0.5),
    'diseases': GenericSitemap(theme_sitemap, priority=0.9),
    'maincategories': GenericSitemap(maincategory_sitemap, priority=0.9),
    'categorydrug': GenericSitemap(categorydrug_sitemap, priority=0.9),
    'drugs': GenericSitemap(drug_sitemap, priority=0.8),
  ....
}




urlpatterns = [
    path('sitemap.xml', sitemap,
        {'sitemaps': sitemaps},
        name='django.contrib.sitemaps.views.sitemap'),
]

Is it correct way of creating sitemap for project of few apps? Should category be created such way? or as static? Does it matter if the sequence of of models: firstly categories and then articles etc? or it doesnt matter? Thank for your attention once again!

Note that the sitemap.xml file is intended for automated indexing. I wouldn’t worry about organizing it for human consumption, unless you’re using it to create your own sitemap page on your site.

Whether you want to create categories is an arbitrary decision. If you’ve got different attributes to set for the different categories, then you can do that. Otherwise, if everything is pretty much the same and you don’t have more than 50,000 urls, I don’t personally see the value in breaking it up.

(I’ve never broken up a sitemap into categories.)

You might want to read sitemaps.org - Protocol.

1 Like