所以查询表中的最前的几条数据的python语言表示为:
# 限制返回的数据 相当于 SQL 中的 OFFSET 0 LIMIT 5;
response4 = 'username排序,取前5个' + '<br>'
list = Account.objects.order_by('username')[0:5]
for value in list:
response4 += value.username + '<br>'
所以查询表中的最近的后条数据的python语言表示为:
response5 = 'username排序,取最后5个' + '<br>'
list = Account.objects.order_by('-id')[:5]
for value in list:
response5 += value.username + '<br>'