Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTML表格不从Django获取数据,只显示标题_Html_Css_Django_Django Models_Django Templates - Fatal编程技术网

HTML表格不从Django获取数据,只显示标题

HTML表格不从Django获取数据,只显示标题,html,css,django,django-models,django-templates,Html,Css,Django,Django Models,Django Templates,我在前端使用HTML、CSS和Javascript,在后端使用Django,在DB中使用PostgresSQL。实际上,我已经成功地将EXCEL文件中的数据加载到Django,并且我正在尝试将数据从Django提取到HTML表中。但是,我只得到表的标题,而不是数据。如何修复它 index.html {%extends "base.html"%} {%block content%} <html> <table> <thead>

我在前端使用HTML、CSS和Javascript,在后端使用Django,在DB中使用PostgresSQL。实际上,我已经成功地将EXCEL文件中的数据加载到Django,并且我正在尝试将数据从Django提取到HTML表中。但是,我只得到表的标题,而不是数据。如何修复它

index.html

{%extends "base.html"%}
{%block content%}

<html>
<table>
  <thead>
      <th>Brand</th>
      <th>Name</th>
  </thead>
  <tbody>
    <tr> 
      <td><strong>{{pro.brand}}</strong></td>
      <td><strong>{{pro.name}}</strong></td>
      </tr>
  </tbody> 
</table>
{%endblock%}
url.py(应用程序文件)


因为您的上下文变量pro是一个queryset(实例列表),所以必须在模板中执行如下循环:

{%extends "base.html"%}
{%block content%}

<html>
<table>
  <thead>
      <th>Brand</th>
      <th>Name</th>
  </thead>
  <tbody>
    {% for p in pro %}
    <tr> 
      <td><strong>{{p.brand}}</strong></td>
      <td><strong>{{p.name}}</strong></td>
    </tr>
    {% endfor %}
  </tbody> 
</table>
{%endblock%}

{%extends“base.html”%}
{%block content%}
烙印
名称
{pro%中p的%s}
{p.brand}
{p.name}
{%endfor%}
{%endblock%}
urlpatterns = [
    path('product/', views.product, name='product'),
]
{%extends "base.html"%}
{%block content%}

<html>
<table>
  <thead>
      <th>Brand</th>
      <th>Name</th>
  </thead>
  <tbody>
    {% for p in pro %}
    <tr> 
      <td><strong>{{p.brand}}</strong></td>
      <td><strong>{{p.name}}</strong></td>
    </tr>
    {% endfor %}
  </tbody> 
</table>
{%endblock%}