##########settings.py
SITE_ID=1# Application definition# taggit tagINSTALLED_APPS = [ 'myblog', 'taggit', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', 'django.contrib.sitemaps']
python manage.py migrate
############sitemaps.py#coding:utf-8__author__ = 'similarface'from django.contrib.sitemaps import Sitemapfrom .models import Postclass PostSitemap(Sitemap): changefreq='weekly' priority=0.9 def items(self): return Post.published.all() def lastmod(self,obj): return obj.publish
#########urls.pyfrom django.conf.urls import urlfrom django.contrib import adminfrom django.conf.urls import includefrom django.contrib.sitemaps .views import sitemapfrom myblog.sitemaps import PostSitemapsitemaps={ 'posts':PostSitemap,}urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^myblog/', include('myblog.urls',namespace='myblog',app_name='myblog')), url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},name='django.contrib.sitemaps.views.sitemap'),]
http://127.0.0.1:8000/sitemap.xml
http://example.com/myblog/2016/04/20/python%E4%BB%A3%E7%A0%81/ 2016-04-20 weekly 0.9 http://example.com/myblog/2016/04/19/ssss/ 2016-04-19 weekly 0.9 ... http://example.com/myblog/2016/04/19/python%20%E6%93%8D%E4%BD%9CFTP/ 2016-04-19 weekly 0.9