0

我在让 Django 设置为我生成站点地图时遇到问题。

我已将以下内容添加到我的设置文件中

'django.contrib.sites',
'django.contrib.sitemaps',

在我的 urls 文件中,我有以下内容:

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')),
]
4

1 回答 1

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()

于 2017-09-01T13:25:45.390 回答