简体   繁体   English

如何使用云Firestore以表格形式获取django中的数据?

[英]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.

相关问题 如何使用Django URL获取由云电话服务发送的数据? - How to get data sent by cloud telephony service using django url? 如何使用 ajax 以 django 中的复选框形式从不同的表中获取数据 - how to get data from different table using ajax in form of checkbox in django 如何在Django(Horizo​​n Dashboard)中使用POST从表单获取数据? - How to get data from form using POST in django (Horizon Dashboard)? 如何获取数据并将其放入Django的编辑表单中 - How to get data and put it into edit form Django 如何获取Django表单的格式化POST数据? - How to get the formatted POST data of a Django form? 如何从Django中的表单获取数据? - How to get a data from form in django? 如何将 HTML 表格中的数据导入 DJango - How to get data from a HTML table into DJango 如何使用Django获取表单中的多个BooleanFields - How get multiple BooleanFields in a form using Django 如何使用 Django 表从 HTML 表单中选择、插入、更新、删除 MySQL 数据库中的数据 - How to select,insert,update,delete data in MySQL database from an HTML form using Django table 在 django 如何在不使用 form.py 的情况下从 html 表中添加数据 - in django how to add data from html table without using form.py
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM