0

My first ever question here, sorry, if somethings off... Basically im having issues with my breadcrumbs generator - im passing in a name of a category which is a query list, then i set tags to be an empty string into which i place a tag which is basically just a string as well, but when i pass it into same def it prints out as None and i cant figure out why... any help would be appreciated! This question is not a duplicate - return is in the right place where it returns a string containing breadcrumbs tags, its meant to loop until it gets inside if and then return executes after that.

   def make_crumb(home, category):
        crumb_middle = ""
        crumb_end = category.category_name_url_friendly + '">' + category.category_name + '</a>'
        while not category.parent_category_id == 0:
            category = Category.query.filter(Category.id == category.parent_category_id).first()
            crumb_middle = category.category_name_url_friendly + '/' + crumb_middle
        crumb_done = home + crumb_middle + crumb_end
        print "crumb done", crumb_done
        return crumb_done


def parent_check(category, breadcrumbs=None, tags=None):
    print "tags", tags
    if not breadcrumbs:
        breadcrumbs = '<a itemprop="breadcrumb" href="https://dev.shopifymarketplace.com/">Home</a>'
    if not tags:
        tags = ""
    pointer = ' &#x21DB;'
    home = '<a itemprop="breadcrumb" href="https://dev.shopifymarketplace.com/categories/'
    # if only one level deep - add category name to home tag
    if category.parent_category_id == 0:
        crumb_done = pointer + home + category.category_name_url_friendly + '">' + category.category_name + '</a>'
        breadcrumbs += crumb_done + tags
    else:
        tags = pointer + make_crumb(home, category) + tags
        parent_check(Category.query.filter(Category.id == category.parent_category_id).first(), tags)
    return breadcrumbs

Output Error:

[Fri Nov 18 15:12:10.848261 2016] [:error] [pid 26720] tags None
[Fri Nov 18 15:12:10.855084 2016] [:error] [pid 26720] crumb done <a itemprop="breadcrumb" href="https://dev.shopifymarketplace.com/categories/art-photography/photo_frames/rectangle/square/gum_gum">gum gum</a>
[Fri Nov 18 15:12:10.856791 2016] [:error] [pid 26720] tags None
[Fri Nov 18 15:12:10.862042 2016] [:error] [pid 26720] crumb done <a itemprop="breadcrumb" href="https://dev.shopifymarketplace.com/categories/art-photography/photo_frames/rectangle/square">square</a>
[Fri Nov 18 15:12:10.864090 2016] [:error] [pid 26720] tags None
[Fri Nov 18 15:12:10.867533 2016] [:error] [pid 26720] crumb done <a itemprop="breadcrumb" href="https://dev.shopifymarketplace.com/categories/art-photography/photo_frames/rectangle">Rectangle</a>
[Fri Nov 18 15:12:10.869289 2016] [:error] [pid 26720] tags None
[Fri Nov 18 15:12:10.871102 2016] [:error] [pid 26720] crumb done <a itemprop="breadcrumb" href="https://dev.shopifymarketplace.com/categories/art-photography/photo_frames">Photo Frames</a>
[Fri Nov 18 15:12:10.872855 2016] [:error] [pid 26720] tags None
  • 1
    This is NOT a duplicate! (or at least not a complete duplicate) The reason is that `parent_check()` is defined with three parameters, but is called with only two arguments, so the third parameter always defaults to `None`. – John Gordon Nov 18 '16 at 15:32
  • its true that its not a duplicate question, but the parameters are set to None only if they are not passed in, since im passing 'tags' string in i dont get why it prints out as None. – Gints Gavars Nov 18 '16 at 15:36
  • You are passing `tags`, but as a positional argument, not a keyword argument. It is the second argument, therefore it appears in the function as the second parameter (breadcrumbs). If you want to pass it as a keyword argument, use that syntax: `parent_check(..., tags=tags)` – John Gordon Nov 18 '16 at 15:39
  • Dude - you'r the best, that worked! Thank you kindly! – Gints Gavars Nov 18 '16 at 15:44

0 Answers0