问题
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
ornews
) to itsSitemap
class (e.g.,BlogSitemap
orNewsSitemap
). It may also map to an instance of aSitemap
class (e.g.,BlogSitemap(some_var)
).
So... define it.
来源:https://stackoverflow.com/questions/10378656/django-nameerror-urls-py