【发布时间】:2020-01-27 20:56:00
【问题描述】:
我的分页有问题,这是我的代码模板
{% for post in post %}
<tr class="text-center">
<td>
{{forloop.counter|add:post.start_index }}
</td>
{%endfor%}
view.py
def rankpag(request):
with connection.cursor() as cursor:
cursor.execute("SELECT c.CharName,gu.GuildName,c.Level,c.Family,c.Sex,c.Job,c.K1,c.K2,Str,Dex,Rec,Int,Luc,Wis,HP,MP,SP,g.Country FROM PS_GameData.dbo.Chars c JOIN PS_UserData.dbo.Users_Master m ON m.UserUID=c.UserUID JOIN PS_GameData.dbo.UserMaxGrow g ON g.UserUID=c.UserUID LEFT JOIN PS_GameData.dbo.GuildChars gc ON (gc.CharID=c.CharID and gc.Del=0) LEFT JOIN PS_GameData.dbo.Guilds gu ON gu.GuildID=gc.GuildID ORDER BY c.K1 DESC")
row = cursor.fetchall()
paginator = Paginator(row,10)
page = request.GET.get('page')
post = paginator.get_page(page)
return render(request,'Ranks.html',{'post':post})
【问题讨论】:
-
嗨,请将 for 循环更改为:{% for po in post %}
{{forloop.counter|add:po.start_index }} {%endfor%} for 循环变量的名称不应与基本变量相同。
标签: python django django-templates django-pagination