0

I'm looking at creating a sitemap based on a list of parameters, but seem to be running into issues. I can get it to work with a single parameter, but not iterate over a list of parameters.

Here is the working code, for a single parameter:

class FinancialViewSitemap(sitemaps.Sitemap):
changefreq = 'weekly'
priority = 0.8

def items(self):
    return ['financials:annuals', 'financials:keymetrics', 'financials:quarterly','financials:peratio'] 

def location(self, item):
    return reverse(item, kwargs={'ticker': 'AAPL'})
    

and here is my attempt at iterating over a list, which does not work:

class FinancialViewSitemap(sitemaps.Sitemap):
changefreq = 'weekly'
priority = 0.8

tickers = ["AAPL", "GOOG", "META"]

for ticker in tickers:
    def items(self):
        return ['financials:annuals', 'financials:keymetrics', 'financials:quarterly','financials:peratio'] 

    def location(self, item, tickers=tickers, ticker = ticker):
        return reverse(item, kwargs={'ticker': ticker})
LBJ33
  • 425
  • 11
  • 29

0 Answers0