2017-09-04 79 views
1

我有問題得到Django安裝程序爲我生成站點地圖。在Django的網站地圖1.10.7

我加入以下到我的設置文件

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

和IM我的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. 

任何想法極大的欣賞編輯。

回答

1

嘗試更換:

url(r'^sitemap.xml$', sitemap, {'sitemaps': {'cmspages': CMSSitemap}}), 
#    ^^^ 

url(r'^sitemap.xml/', sitemap, {'sitemaps': {'cmspages': CMSSitemap}}), 
#    ^^^ 
+0

這已經解決了這個問題,非常感謝您的幫助。 –

+0

很高興爲您效勞,不要忘記接受答案 –

0

我認爲這是一個緩存的問題。

    在瀏覽器中,然後打開 http://xxxxxxxxxxxxxx.co.uk/sitemap.xml沒有shalsh (/)
  • 打開新的隱身窗口

OR:

  • 清除緩存,然後再重新打開您的http://xxxxxxxxxxxxxx.co.uk/sitemap.xml沒有shalsh (/)

Don't miss to change: sitemap.xml to sitemap\.xml like this source .

+0

感謝您對此的迴應,如果沒有結尾斜槓,它確實會呈現.xml文件 –