2012-04-30 90 views
1

當我嘗試將站點地圖與我的應用程序集成時,我從我的urls.py中獲取名稱錯誤:name sitemaps is not definedDjango NameError urls.py

從我的urls.py:

from django.contrib.sitemaps import Sitemap 

(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}), 

有什麼問題從我的urls.py這個正則表達式?還是有另一個問題呢?

感謝您的輸入

回答

2

一般來說,你會做這樣的事情 -

from django.contrib.sitemaps import Sitemap, FlatPageSitemap 

sitemaps = { 
    'site': Sitemap, 
    'flatpages': FlatPageSitemap, 
} 

# .. 
# Some url patterns. urlpatterns must be defined by now 
# .. 

urlpatterns += patterns("", 
    url(r'^sitemap\.xml$', 
     'django.contrib.sitemaps.views.sitemap', 
     {'sitemaps': sitemaps} 
), 
) 
+0

非常有幫助。非常感謝你 –

0

the docs

sitemaps should be a dictionary that maps a short section label (e.g., blog or news) to its Sitemap class (e.g., BlogSitemap or NewsSitemap). It may also map to an instance of a Sitemap class (e.g., BlogSitemap(some_var)).

所以...定義它。