[Answer]-Expand url django patterns

1๐Ÿ‘

Ok i have to answer my own question because i solved it, what i did was a little function to expand the patterns like this

def expand_patterns(patterns):
    new_patterns = []
    def recursive_expand(patterns):
        for p in patterns:
            if getattr(p,'url_patterns',False):
                recursive_expand(p.url_patterns)
            else:
                new_patterns.append(p)
    recursive_expand(patterns)
    return new_patterns

This will flatten out the urlpatterns into a single list.
So now i can use self.patterns to filter out anything in my Sitemap class ๐Ÿ™‚

Leave a comment