[英]How to get data in the form of table in django using cloud firestore?
1 2 3 1 2 3
I'm trying to get data in the form of a table, but the data is not being fetched, I don't know how to get the record, I'm using cloud firestore to get the data.我正在尝试以表格的形式获取数据,但是没有获取数据,我不知道如何获取记录,我正在使用云火库来获取数据。
In my code I have used {{buldings.building}} to get the record but this is not fetching the record from the firebase.在我的代码中,我使用 {{buldings.building}} 来获取记录,但这不是从 firebase 获取记录。
here is my table code for table这是我的表格代码
<div class="row">
<div class="col-lg-12 mb-4">
<!-- Simple Tables -->
<div class="card">
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
<a href="{% url 'building:registerBuilding'%}" class="btn btn-sm btn-primary"><i class="fas fa-plus-circle "></i> Add Building</a>
</div>
<div class="table-responsive">
<table class="table align-items-center table-flush" id="buildingList">
<thead class="thead-light">
<tr>
<th>BUILDING NAME</th>
<th>POSTAL CODE</th>
<th>CITY</th>
<th>STREET</th>
<th>HOUSE NO.</th>
<th>TOWN</th>
<th>ADDITIONAL INFO</th>
<th colspan="2">ACTION</th>
</tr>
</thead>
<tbody>
{% for building in buildings %}
<tr>
<td>{{ buildings.building }}</td>
<td>{{ buildings.postalCode }}</td>
<td>{{ buildings.city }}</td>
<td>{{ buildings.houseNo }}</td>
<td>{{ buildings.street }}</td>
<td>{{ buildings.town }}</td>
<td>{{ buildings.additionalInfo }}</td>
<td><a href="#" class="btn btn-primary btn-xs" data-title="Edit" ><i class="glyphicon glyphicon-pencil"></i>Edit</a></p></td>
<td><a href="#" class="btn btn-danger btn-xs" data-title="Delete" ><i class="glyphicon glyphicon-trash"></i>Delete</a></p></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="card-footer"></div>
</div>
</div>
</div>
</div>
<!---Container Fluid-->
</div>
views.py file视图.py 文件
def buildingMag(request):
context = {
'buildings': db.collection('Buildings').get()
}
return render(request,"EmployeeAdmin/buildingMag.html",context)
db.collection('Buildings').get()
should return you a list of Firestore DocumentSnapshot
which is sent to template context via buildings
key. db.collection('Buildings').get()
应该返回一个 Firestore DocumentSnapshot
列表,该列表通过buildings
键发送到模板上下文。 Looping through the buildings
will let you populate the template(table) with each item on the list.遍历
buildings
将让您使用列表中的每个项目填充模板(表格)。 Something like below.像下面的东西。
In your views construct the dict from DocumentSnapshot
and return the dict在您的视图中,从
DocumentSnapshot
构造字典并返回该字典
views.py视图.py
buildings = db.collection('Buildings').get()
context = {
'buildings': [building.to_dict() for building in buildings]
}
template.html模板.html
{% for building_obj in buildings %}
<tr>
<td>{{ building_obj.building }}</td>
<td>{{ building_obj.postalCode }}</td>
<td>{{ building_obj.city }}</td>
...
...
</tr>
{% endfor %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.