2012-04-30 67 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)).

所以...定义它。