Questions about the use of for loops in django

25 views
Skip to first unread message

jiang hao

unread,
Dec 17, 2022, 6:59:15 PM12/17/22
to Django users
I use a for loop in django. When I refresh the browser, the result of the first for loop is not cleared, and the result of the second for loop is stitched together with the first one.

test.html:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<table border="1">
<thead>
<tr>
<th id="1">full_name</th>
<th id="2">html_url</th>
<th id="3">description</th>
<th id="4">stargazers_count</th>
</tr>
</thead>
<tbody>
{% for item in resp_list %}
<tr>
<td>{{ item.full_name }}</td>
<td>{{ item.html_url }}</td>
<td>{{ item.description }}</td>
<td>{{ item.stargazers_count }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>


Among them, the resp_list here is a list obtained by saving the content I crawled from the Internet using python's requests library.

When I ran the program for the first time, there was no problem. When I refreshed my browser, the first loop was not cleared, which caused the second loop to be followed by the first loop.

I'm desperate for your help, thanks to everyone here!

jiang hao

unread,
Dec 17, 2022, 11:59:29 PM12/17/22
to Django users
I have solved this problem, it is my backend code's problem   :(
Reply all
Reply to author
Forward
0 new messages