首页 > 解决方案 > 如何将表格的数据从 Html 传输到 view.py (Python)

问题描述

我正在使用 Django,我想将一些数据转换为 view.py。我想知道是否有指南或方法可以做到这一点。假设我想将以下内容转换为 view.py

<table class="table table-bordered table-striped">
                  <thead>
                    <!-- Columnas de la tabla -->
                    <tr>
                      <th scope="col">Nombre huesped</th>
                      <th scope="col">Rut huesped</th>
                      <th scope="col">Telefono</th>
                      <th scope="col">N° de habitacion</th>
                      <th scope="col">Tipo de plato</th>
                      <th scope="col">borrar</th>
                      
                    </tr>
                  </thead>
                  <tbody id="filas">
                    <!-- Fila 1 de la tabla -->
                    
                  </tbody>
                </table>

标签: pythonhtmldjango

解决方案


我认为这可以通过将其作为 HTTPResponse 返回来实现:

def index(request):
   return HttpResponse("""<table class="table table-bordered table-striped">
                  <thead>
                    <!-- Columnas de la tabla -->
                    <tr>
                      <th scope="col">Nombre huesped</th>
                      <th scope="col">Rut huesped</th>
                      <th scope="col">Telefono</th>
                      <th scope="col">N° de habitacion</th>
                      <th scope="col">Tipo de plato</th>
                      <th scope="col">borrar</th>
                      
                    </tr>
                  </thead>
                  <tbody id="filas">
                    <!-- Fila 1 de la tabla -->
                    
                  </tbody>
                </table>""")

推荐阅读