我正在尝试在我的 django 应用程序中实现站点地图,但出现以下错误。我正在使用 django 站点地图的框架。我不知道我做错了什么。
Traceback:
File "mysite/urls.py" in <module>
3. from sitemap import *
File "mysite/sitemap.py" in <module>
5. class Sitemap(sitemaps.Sitemap):
Exception Type: NameError at /
Exception Value: name 'sitemaps' is not defined
这是 sitemap.py 文件
from django.contrib.sitemaps import Sitemap
from meddy1.models import Doctor
import datetime
class Sitemap(Sitemap):
def __init__(self, names):
self.names = names
def items(self):
return self.names
def changefreq(self, obj):
return 'weekly'
def lastmod(self, obj):
return datetime.datetime.now()
def location(self, obj):
return reverse(obj)
class DoctorSitemap(Sitemap):
changefreq = "Daily"
priority = 1
def items(self):
return Doctor.objects.all()
def lastmod(self, obj):
return obj.date
这是 urls.py 文件
from django.conf.urls import patterns, include, url
from django.contrib import admin
from sitemap import *
admin.autodiscover()
sitemaps = {
'pages':Sitemap(['homepage_imprint', 'homepage_archive']),
'doctor':DoctorSitemap,
'site':Sitemap(['name_of_url', 'name_of_url']),
}
urlpatterns = patterns('',
url(r'^', include('meddy1.urls')),
url(r'^', include('django.contrib.auth.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^sitemap\.xml', include('django.contrib.sitemaps.views.sitemap'),{'sitemaps': sitemaps}),
)