Django NameError urls.py

老子叫甜甜 提交于 2019-12-23 03:03:18

问题


Im getting a name error: name sitemaps is not defined from my urls.py when I try to integrate sitemaps with my application.

From my urls.py:

from django.contrib.sitemaps import Sitemap

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

Is there something wrong with this regular expression from my urls.py? Or is there another problem going on?

Thanks for your input


回答1:


Generally you will do something like this -

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}
  ),
)



回答2:


From 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)).

So... define it.



来源:https://stackoverflow.com/questions/10378656/django-nameerror-urls-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!