######### #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 ':P ostsitemap,}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
<Urlsetxmlns= "http://www.sitemaps.org/schemas/sitemap/0.9"><URL><Loc>http://example.com/myblog/2016/04/20/python%E4%BB%A3%E7%A0%81/</Loc><Lastmod>2016-04-20</Lastmod><Changefreq>Weekly</Changefreq>< Priority>0.9</ Priority></URL><URL><Loc>http://example.com/myblog/2016/04/19/ssss/</Loc><Lastmod>2016-04-19</Lastmod><Changefreq>Weekly</Changefreq>< Priority>0.9</ Priority></URL><URL><Loc>http://example.com/myblog/2016/04/19/python%20%E6%93%8D%E4%BD%9CFTP/</Loc><Lastmod>2016-04-19</Lastmod><Changefreq>Weekly</Changefreq>< Priority>0.9</ Priority></URL>...
Django's Sitemap