我在让Django设置为我生成站点地图时遇到了问题。
我已将以下内容添加到我的设置文件
中'django.contrib.sites',
'django.contrib.sitemaps',
在我的网址文件中,我有以下内容:
from django.conf.urls import include, url
from django.contrib import admin
from ames import views
from cms.sitemaps import CMSSitemap
admin.autodiscover()
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^contact/', include('contact.urls')),
url(r'^news/', include('news.urls')),
url(r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': {'cmspages': CMSSitemap}}),
url(r'^$', views.home),
url(r'^', include('cms.urls')),
]
部署这些修正时,我在网站上收到以下错误:
TypeError at /sitemap.xml/
view must be a callable or a list/tuple in the case of include().
任何想法都会受到欢迎。
修改了urls.py文件:
from django.conf.urls import include, url
from django.contrib import admin
from cms.sitemaps import CMSSitemap
from django.contrib.sitemaps.views import sitemap
from ames import views
admin.autodiscover()
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^contact/', include('contact.urls')),
url(r'^news/', include('news.urls')),
url(r'^sitemap.xml$', sitemap, {'sitemaps': {'cmspages': CMSSitemap}}),
url(r'^$', views.home),
url(r'^', include('cms.urls')),
]
答案 0 :(得分:0)
试一试:
from django.contrib.sitemaps.views import sitemap
# you code
url(r'^sitemap.xml$', sitemap, {'sitemaps': {'cmspages': CMSSitemap}}),
并删除
url(r'^sitemap.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': {'cmspages': CMSSitemap}}),
解决方案的所有信息均错误view must be a callable or a list/tuple in the case of include()