Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

https://teamtreehouse.com/library/django-basics/model-administration/first-app-view-2 Be sure to use the len() ??

How can I use the len() Code: from django.http import HttpResponse from articles.models import Article

def article_list(request): courses = Article.objects.all() output = ', '.join(len(course) for course in courses) return HttpResponse(output)

2 Answers

Hey Andi Gela,

What you have to do, is get the number of articles and display that, in the output.

In order to do so, you need to use Python's len() function, passing in whatever is returned by querying the Article Model: articles = Article.objects.all()

Then use the query stored in the 'articles' variable as the argument in the len() function: output = "There are {} articles".format( len(articles) )

Then, you can pass the 'output' variable to the HttpResponse() class, and return it.

Good Luck!

Thank You

No problem, Andi.