要实现类似下面的
一般情况是 先在后端实现 再在前端渲染
后端
parent_object = models.FileRepository.objects.filter( id=int(folder_id), file_type=2, project=request.tracer.project).first()
# 做导航栏 breadcrumb_list = [] parent = parent_object while parent: breadcrumb_list.insert(0, {'id': parent.id, 'name': parent.name}) parent = parent.parent
# 传到前端
return render(request, 'file.html',
{'breadcrumb_list':breadcrumb_list})
前端
<div> <a href="{% url 'file' project_id=request.tracer.project.id %}"> <i class="fa fa-home" aria-hidden="true"></i> <span>文件库</span> </a> {% for record in breadcrumb_list %} <a href="{% url 'file' project_id=request.tracer.project.id %}?folder={{ record.id }}"> <i class="fa fa-caret-right" aria-hidden="true"></i> <span>{{ record.name }}</span> </a> {% endfor %} </div>