pythondjangoamazon-web-servicesdjango-sitemaps

Django 1.6: name 'Sitemap' is not defined


I'm stuck into this issue on Django 1.6

This is my sitemaps.py

from django.contrib import sitemaps
from django.core.urlresolvers import reverse

from datetime import datetime

class ContratalosSitemap(Sitemap):

def __init__(self, names):
    self.names = names

def items(self):
    return self.names

def changefreq(self, obj):
    return 'weekly'

def lastmod(self, obj):
    return datetime.now()

This is my urls.py

from django.conf.urls import patterns, include, url
from django.conf import settings
from django.contrib import admin
from django.contrib.sitemaps import Sitemap
from sitemaps.py import ContratalosSitemap

#Declaration for sitemaps url

sitemaps = {
    'pages' : ContratalosSitemap,
}

urlpatterns = patterns(
'apps.contratalos.views',
url(r'c/(?P<slug>\.*[^ ]{1,128})?/', 'c', name='content'),
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap',    {'sitemaps'$
)

I'm stuck into this, what could be the cause?

I followed this and this

But no luck yet =/

Any ideas please?

Thanks in advance!


Solution

  • With import sitemap you only imported the module name. So if you want to use something in the module, you would need too write sitemap.Sitemap.

    If you write from sitemap import Sitemap you specifically import the Sitemap class from the module and can use it directly, just like in your code.

    You can also do from sitemap import *, which will import all definitions in the module. But it is not recommend, since you probably only use a few names from it.