Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用Flask构建treeview?_Python_Html_Flask_Treeview - Fatal编程技术网

Python 如何使用Flask构建treeview?

Python 如何使用Flask构建treeview?,python,html,flask,treeview,Python,Html,Flask,Treeview,我正在尝试使用Flask构建一个treeview。我正在从数据库中提取数据,并尝试将它们显示为树。我设法显示父文件夹,但子文件夹出现问题 这是一个树的屏幕: 下面是一些代码: Python代码来自Flask。此处文件夹分为父文件夹和子文件夹: Html代码与Jinja2。在这里,我试图构建这棵树: {父行%中的父行为%0} {{parent[1]} {child_row%}中的子项为% {%如果父[0]==子[2]} {{child[1]} {%endif%} {%endfor%} {%

我正在尝试使用
Flask
构建一个
treeview
。我正在从数据库中提取数据,并尝试将它们显示为树。我设法显示父文件夹,但子文件夹出现问题

这是一个树的屏幕:

下面是一些代码:

  • Python
    代码来自
    Flask
    。此处文件夹分为父文件夹和子文件夹:
  • Html
    代码与
    Jinja2
    。在这里,我试图构建这棵树:
  • 
    
      {父行%中的父行为%0}
    • {{parent[1]} {child_row%}中的子项为% {%如果父[0]==子[2]}
      • {{child[1]}
        • {%endif%} {%endfor%} {%endfor%}
    问题: 我怎样才能造一棵树

    parent_directory = []
    child_directory = [] 
    def filter(rt):
        for foldre_ID in rt:
            if foldre_ID[2] == None:
                print(f'Parent dir - {foldre_ID}')
                parent_directory.append(foldre_ID)
            else:
                print(f'Child dir - {foldre_ID}')
                child_directory.append(foldre_ID)
        print(child_directory)
        parent_child(parent_directory, child_directory)
        return render_template('tree_view.html', parent_row=parent_directory, child_row=child_directory)
    
    <body>
        <ul>
            {% for parent in parent_row %}
            <li><input type="checkbox" id="{{ parent }}"><label for="{{ parent }}">{{ parent[1] }}</label>
                {% for child in child_row %}
                    {% if parent[0] == child[2] %}
                <ul><li><input type="checkbox" id="{{ child }}"><label for="{{ child }}">{{ child[1] }}</label></li></ul>
                    {% endif %}
                {% endfor %}
            </li>
            {% endfor %}
        </ul>
    </body>