These are chat archives for django/django

4th
Jan 2018
Prateek Dabas
@dprateek11
Jan 04 2018 12:50
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)
what is this function doing?
[:5] - what does this means
and i don't understand the value of output
avocadosarelife
@avocadosarelife
Jan 04 2018 13:56
I see, thank you @bittner and @anjansrivathsav it is working now : )

@dprateek11 [:5] gives you the first 5 elements, I think
if you have a list, it would do exactly that, and I think that works for objects too

list = [1, 2, 3, 4, 5, 6, 7]
print(list[:5])
[1, 2, 3, 4, 5]

Prateek Dabas
@dprateek11
Jan 04 2018 14:00
@avocadosarelife thank you
Vatslau
@VatslauX
Jan 04 2018 18:10
Hi all, for API testing django +- - could You advise