-2

Exception Value:

cannot concatenate 'str' and 'NoneType' objects

class BrandSitemap(Sitemap):
    def items(self):
        return Page.objects.filter(parent__title=u'Бренды').values(
            'short_url', 'publish_date')

    def location(self, obj):
        return '/brand/' + obj['short_url']

    def lastmod(self, obj):
        return obj['publish_date']

how to clean up obj['short_url'] in end of the url all the numbers? for example: before:agent-provocateur-1 after: agent-provocateur

def location(self, obj): return '/brand/' + str(obj['short_url'])

1 Answers1

0

Try the following:

if 'short_url' in obj:
   return '/brand/' + obj['short_url']
else:
   return '/error/'  # missing short_url so this may be an error you need to handle

Which could be shortened to

return '/brand/' + obj['short_url'] if 'short_url' in obj else '/error/'

You've also have obj['publish_date']</i> which i can't tell if this is a typo or you are literally trying to just put that in there...

you should however look at what should be populating short_url in your obj - you may be calling things out of order or it's not being populated with what you believe it to be.

Mike McMahon
  • 7,096
  • 3
  • 30
  • 42