[Django]-Django 1.6: name 'sitemaps' is not defined

2๐Ÿ‘

You imported Sitemaps from the module, not the module itself. Remove the module name:

class Sitemap(Sitemap):

This will just about work, even though you are replacing the imported class here.

Alternatively and arguably clearer as to what you are doing, adjust your import of the module. Change the import from:

from django.contrib.sitemaps import Sitemap

to:

from django.contrib import sitemaps
๐Ÿ‘คMartijn Pieters

0๐Ÿ‘

Martijn already provided correct answer, I just want to add a more general note about namespaces in Python: every name you use in Python has to come from somewhere. There is a number of built-in names that are always available, e.g. dir(). Other than the built-ins, every name has to be either created in your own code in the module OR imported from some other module or package:

>>> x
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
>>> x = 1
>>> x
1
>>> sys
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'sys' is not defined
>>> import sys
>>> sys
<module 'sys' (built-in)>
๐Ÿ‘คRainy

0๐Ÿ‘

Simply change the s in sitemap to lowercase and add .views to the import line. therefore the new import should be "from django.contrib.sitemaps.views import sitemap"

๐Ÿ‘คEnock Koech

Leave a comment