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!
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
def article_list(request): output = Article.len() return HttpResponse('There are ' + output + ' articles.')
I think I have an error in my syntax, but I am not sure. Any hints??
from django.http import HttpResponse from .models import Article # Write your views here def article_list(request): output = Article.len() return HttpResponse('There are ' + output + ' articles.')
Chris FreemanTreehouse Moderator 68,388 Points
You are very close. Remember, to get all of the
Article instances in Django you need to use the model manager:
This returns a
queryset of all results. you can then use the
len() function (not a method!) on this queryset to get the number of objects.
Also, remember to convert your length result to a string before using concatenation:
str(output). Alternatively, you could use a
.format() statement that auto converts
output to a string for you!
Post back if you're still stuck. Good Luck!!!