我被这个错误卡住了我是Django的新用户我正在正确地遵循步骤并通过YT.学习
当我运行python manage.py runserver时,HTML显示
我的index.html文件
<!DOCTYPE html>
<header>
CRUD Operation with PostgreSQL
</header>
<body>
<center>
<h1>How to create CURD Ops with PostgreSQL</h1>
<h3>Learning Django and CURD</h3>
<hr/>
<table border = "1">
<tr>
<th>Employee Id</th>
<th>Employee Name</th>
<th>Email</th>
<th>Occupation</th>
<th>Salary</th>
<th>Gender</th>
</tr>
{% for results in data% }
<tr>
<td>{{result.id}}</td>
<td>{{result.name}}</td>
<td>{{result.email}}</td>
<td>{{result.occupation}}</td>
<td>{{result.salary}}</td>
<td>{{result.gender}}</td>
</tr>
{% endfor %}
</table>
</center>
</body>
我试着把endfor改成endblock什么都不管用。我不知道怎么解决这个问题。
在这里查看您的代码:
{% for results in data% }
<tr>
<td>{{result.id}}</td>
<td>{{result.name}}</td>
<td>{{result.email}}</td>
<td>{{result.occupation}}</td>
<td>{{result.salary}}</td>
<td>{{result.gender}}</td>
</tr>
{% endfor %}
您需要将{% for results in data% }
更改为{% for result in data %}
。注意,当你在循环中使用单数result
时,放空格并查看复数results
的地方。