问题描述
我正在使用 IFC,我需要从 .ifc 文件中提取一些数据以显示在 Django 模板中。
模板:
{% extends 'base.html' %}
{% block content %}
<h2>upload</h2>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="file" name="document">
<button type="submit">Upload File</button>
</form>
<br>
{{result}}
{% endblock %}
我尝试了两种方法:
OpenIfcFile = ifcopenshell.open(filepath) #select the file
BrowseIfcProducts = OpenIfcFile.by_type('IfcElement') #search for the attribute 'IfcElement'
for eachproduct in BrowseIfcProducts:
#add the .ifc searched data to dict 'context' with 'result' key
context['result'] =
[
eachproduct.is_a(),eachproduct.GlobalId,eachproduct.get_info()["type"],eachproduct.get_info().get("Name","error"),]
return render(request,'upload.html',context)
在这种方法中,由于每次迭代的关键“结果”不会改变,只存储最后一个项目,在我的模板中我看不到所有项目。
因此,为了解决这个问题,我将结果键连接到迭代器 (i):
i = 1
for eachproduct in BrowseIfcProducts:
context['{} {}'.format('result',i)] = [
eachproduct.is_a(),]
i += 1
return render(request,context)
但不幸的是,模板中没有显示任何内容
我被困在这里,我不知道如何在模板上显示数据,有人可以帮助我吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)