Django 1.10.7 中的站点地图
Sitemap in Django 1.10.7
我在设置 Django 为我生成站点地图时遇到问题。
我已将以下内容添加到我的设置文件
'django.contrib.sites',
'django.contrib.sitemaps',
我的 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')),
]
部署这些文件后,我应该能够在 /sitemap.xml 看到 .xml 文件,但我收到 404 错误:
Page not found (404)
Request Method: GET
Request URL: http://xxxxxxxxxxxxxx.co.uk/sitemap.xml/
Raised by: cms.views.details
Using the URLconf defined in ames.urls, Django tried these URL patterns, in this order:
^admin/
^contact/
^news/
^sitemap.xml$
^$
^ ^cms_wizard/
^ ^(?P<slug>[0-9A-Za-z-_.//]+)/$ [name='pages-details-by-slug']
^ ^$ [name='pages-root']
The current URL, /sitemap.xml/, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
非常感谢任何想法。
尝试替换:
url(r'^sitemap.xml$', sitemap, {'sitemaps': {'cmspages': CMSSitemap}}),
# ^^^
至
url(r'^sitemap.xml/', sitemap, {'sitemaps': {'cmspages': CMSSitemap}}),
# ^^^
我以为是缓存问题。
- 在浏览器中打开 new incognito window 然后打开
http://xxxxxxxxxxxxxx.co.uk/sitemap.xml
without shalsh (/)
.
或:
- 清除缓存然后再次重新打开您的
http://xxxxxxxxxxxxxx.co.uk/sitemap.xml
而不使用 shalsh (/)
。
Don't miss to change: sitemap.xml
to sitemap\.xml
like this source.
我在设置 Django 为我生成站点地图时遇到问题。
我已将以下内容添加到我的设置文件
'django.contrib.sites',
'django.contrib.sitemaps',
我的 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')),
]
部署这些文件后,我应该能够在 /sitemap.xml 看到 .xml 文件,但我收到 404 错误:
Page not found (404)
Request Method: GET
Request URL: http://xxxxxxxxxxxxxx.co.uk/sitemap.xml/
Raised by: cms.views.details
Using the URLconf defined in ames.urls, Django tried these URL patterns, in this order:
^admin/
^contact/
^news/
^sitemap.xml$
^$
^ ^cms_wizard/
^ ^(?P<slug>[0-9A-Za-z-_.//]+)/$ [name='pages-details-by-slug']
^ ^$ [name='pages-root']
The current URL, /sitemap.xml/, didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
非常感谢任何想法。
尝试替换:
url(r'^sitemap.xml$', sitemap, {'sitemaps': {'cmspages': CMSSitemap}}),
# ^^^
至
url(r'^sitemap.xml/', sitemap, {'sitemaps': {'cmspages': CMSSitemap}}),
# ^^^
我以为是缓存问题。
- 在浏览器中打开 new incognito window 然后打开
http://xxxxxxxxxxxxxx.co.uk/sitemap.xml
without shalsh(/)
.
或:
- 清除缓存然后再次重新打开您的
http://xxxxxxxxxxxxxx.co.uk/sitemap.xml
而不使用 shalsh(/)
。
Don't miss to change:
sitemap.xml
tositemap\.xml
like this source.