我们还可以指定逆向排序,在前面加一个减号 - 前缀:
1 2 |
|
from django.http import HttpResponse
from .models import Question
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
output = ', '.join([q.question_text for q in latest_question_list])
return HttpResponse(output)
# Leave the rest of the views (detail, results, vote) unchanged
逆向排序,
选择数组中的几个元素,
列表解析式,
https://docs.djangoproject.com/zh-hans/2.1/intro/tutorial03/#write-views-that-actually-do-something
扫描二维码关注公众号,回复:
3637636 查看本文章