我的第一个问题,抱歉,如果有些事情...... 基本上我的面包屑发生器有问题 - 我传递一个类别的名称是一个查询列表,然后我将标签设置为一个空字符串,我放置一个标签,基本上只是一个字符串,但当我将它传递到相同的def时,它打印出来没有,我无法弄清楚为什么......任何帮助将不胜感激! 这个问题不是重复的 - 返回是在正确的位置,它返回一个包含breadcrumbs标签的字符串,它意味着循环,直到它进入内部,然后返回执行后。
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 = ' ⇛'
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
输出错误:
[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