Django has its own sitemap framework for generating XML files
Django Sitemap Demo:
Sitemap is very important, can be used to inform the Search engine page address, the importance of the page, help the site to get a better collection.
To turn on the sitemap feature
Django.contrib.sitemaps and Django.contrib.sites in the settings.py file are to be in Install_apps
Installed_apps = ( ' django.contrib.admin ', ' Django.contrib.auth ', ' django.contrib.contenttypes ', ' django.contrib.sessions ', ' django.contrib.messages ', ' django.contrib.staticfiles ', ' Django.contrib.sites ', ' django.contrib.sitemaps ', ' django.contrib.redirects ', ##### #othther Apps #####)
Django 1.7 and Previous versions:
Template_loaders to join the ' django.template.loaders.app_directories. Loader ', like this:
Template_loaders = ( ' django.template.loaders.filesystem.Loader ', ' Django.template.loaders.app_ Directories. Loader ',)
Django 1.8 and later adds a new templates setting, where App_dirs is true, such as:
# Notice:code for Django 1.8, no work on Django 1.7 and belowtemplates = [ { ' backend ': ' Django.template.backend S.django.djangotemplates ', ' DIRS ': [ os.path.join (Base_dir, ' Templates '). replace (' \ \ ', '/'), ], ' App_dirs ': True, },]
Then configure the following in the urls.py:
From django.conf.urls import urlfrom django.contrib.sitemaps import Genericsitemapfrom django.contrib.sitemaps.views Import sitemap from blog.models import Entry sitemaps = { ' blog ': Genericsitemap ({' Queryset ': Entry.objects.all (), ' Date_field ': ' Pub_date '}, priority=0.6), # If you want to add another can imitate the above} urlpatterns = [ # Some generic view using Info_d ICT # ... # the Sitemap url (r ' ^sitemap\.xml$ ', sitemap, {' Sitemaps ': sitemaps}, name= ' Django.contrib.sitemaps.views.sitemap '),
But this generated sitemap, if the site content too much is very slow, very resource-intensive, you can use the paging function:
From django.conf.urls import urlfrom django.contrib.sitemaps import Genericsitemapfrom django.contrib.sitemaps.views Import sitemap from blog.models import Entry from django.contrib.sitemaps import views as Sitemaps_viewsfrom Django.views. Decorators.cache Import cache_page sitemaps = { ' blog ': Genericsitemap ({' Queryset ': Entry.objects.all (), ' Date_field ': ' Pub_date '}, priority=0.6), # If you want to add other can imitate the above} urlpatterns = [ url (R ' ^sitemap\.xml$ ', cache _page (86400) (Sitemaps_views.index), {' sitemaps ': sitemaps, ' sitemap_url_name ': ' Sitemaps '}), url (r ' ^ sitemap-(? p<section>.+) \.xml$ ', cache_page (86400) (Sitemaps_views.sitemap), {' Sitemaps ': sitemaps}, Name= ' Sitemaps '),]
This allows you to see a sitemap similar to the following if the local test accesses the Http://localhost:8000/sitemap.xml
Django: Sitemap Sitemap, common view, and context renderer