我有一个根文件夹,其中包含其他文件夹和XML文件。我想在我的网页上显示文件夹内容,就像在windows-explorer中一样。例如:
folder_1
txt_file_1
txt_file_2
folder_2
folder_3
txt_file_3如何以这种方式呈现目录?
发布于 2020-07-27 23:09:23
我有一个类似的用例,我能够通过递归地包含一个模板来解决这个问题。
在我的主模板中,我开始了递归:{% include "myapp/tree.html" with children=list_of_objects %}
在tree.html文件中,实际的递归发生在:
{% for child in children %}
{% include "myapp/tree.html" with children=list_of_objects %}
{% endfor %}
您仍然需要从视图中返回目录的列表/字典(或者可能是create a custom template tag来处理它)。
https://stackoverflow.com/questions/63115609
复制相似问题