2013-03-06 81 views
0

我正在爲我的新站點創建站點地圖。靜態頁面的Django站點地圖

該網站只包含靜態頁面。

我試圖讓這個片段的工作:

class StaticSitemap(sitemaps.Sitemap): 
"""Return the static sitemap items""" 
priority = 0.5 

def __init__(self, patterns): 
    self.patterns = patterns 
    self._items = {} 
    self._initialize() 

def _initialize(self): 
    for p in self.patterns: 
     if getattr(p, 'name', None) is not None: 
      print p.name 
      self._items[p.name] = self._get_modification_date(p) 

def _get_modification_date(self, p): 
    template = getattr(p, 'template', None) 
    template_path = self._get_template_path(template) 
    mtime = os.stat(template_path).st_mtime 
    return datetime.datetime.fromtimestamp(mtime) 

def _get_template_path(self, template_path): 
    for template_dir in settings.TEMPLATE_DIRS: 
     path = os.path.join(template_dir, template_path) 
     if os.path.exists(path): 
      return path 

    return None 

def items(self): 
    return self._items.keys() 

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

def lastmod(self, obj): 
    return self._items[obj] 

def location(self, obj): 
    return reverse(obj) 

,我從該行獲得模板此KeyError異常:template = p.default_args['template']

我怎樣才能得到模板的名稱?

回答

0

讓它工作。 剛剛添加模板到每個url的kwargs