HTML表格不从Django获取数据,只显示标题
我在前端使用HTML、CSS和Javascript,在后端使用Django,在DB中使用PostgresSQL。实际上,我已经成功地将EXCEL文件中的数据加载到Django,并且我正在尝试将数据从Django提取到HTML表中。但是,我只得到表的标题,而不是数据。如何修复它 index.htmlHTML表格不从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>
{%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%}