三级菜单渲染

def menu_data(request):
    # 主菜单
    menus = []
    # 二级菜单
    second_level_menu = []
    # 三级菜单
    three_level_menu = []

    # 方法

    k = -1  # ****
    for i in get_menu:
        get_second_level_menu = MenuManager.get_second_level_menu(i.id)
        menus.append(i)
        k += 1
        second_level_menu.append(get_second_level_menu)
        three_level_menu.append([])  # ****
        for j in second_level_menu[k]:
            get_three_level_menu = MenuManager.get_three_level_menu(j.id)
            three_level_menu[k].append(get_three_level_menu)


    print menus
    print second_level_menu
    print three_level_menu
------------------------------------------------
打印结果:
[1>, 2>, 3>]

[[,,],[,],[,]]

[[[,],[,],[]],[[,],[,]],[[,],[,]

三级菜单渲染_第1张图片

以上是从数据库中取出的数据,现在需要html渲染

<li class="grid" style="display: inline;"><a class="color1" href="index.html">首页a>li>



<li class="active grid" style="display: inline;"><a class="color2" href="#">主菜单1a>

<div class="megapanel" style="display: none; opacity: 1;">
<div class="row">

<div class="col1">
<div class="h_nav">
<h4>二级菜单1_1h4>
<ul>
<li><a href="women.html">三极菜单1_1_1a>li>
<li><a href="women.html">三极菜单1_1_2a>li>
<li><a href="women.html">三极菜单1_1_3a>li>

ul>
div>
div>

<div class="col1">
<div class="h_nav">
<h4>二极菜单1_2h4>
<ul>
<li><a href="women.html">三极菜单1_2_1a>li>
<li><a href="women.html">三极菜单1_2_2a>li>
<li><a href="women.html">三极菜单1_2_3a>li>

ul>
div>
div>
<div class="col1">
<div class="h_nav">
<h4>二极菜单1_3h4>
<ul>
<li><a href="women.html">三极菜单1_3_1a>li>
<li><a href="women.html">三极菜单1_3_2a>li>

ul>
div>
div>
div>
<div class="row">
<div class="col2">div>
<div class="col1">div>
<div class="col1">div>
<div class="col1">div>
<div class="col1">div>
div>
div>
li>

渲染方法

a = -1
    f_m_t = ''
    for i in menus:
        f_m_t += '
  • '+str(i)+'
  • 你可能感兴趣的:(项目)