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 Django Basics Model Administration First app view

yelmi almonte
yelmi almonte
10,685 Points

What is the problem in this code? Please arti = Article.objects.all() return HttpResponse("There are "+ arti.len())

arti = Article.objects.all() return HttpResponse("There are "+ arti.len())

i did too

return HttpResponse("There are {0}". format(arti.len()))

articles/views.py
from django.http import HttpResponse
from .models import Article
# Write your viewdef article_list s here
def article_list(request):
    arti =  Article.objects.all()
    return HttpResponse("There are articles " + arti.len())

1 Answer

len is a built-in function, not a method that can be run on Django object sets or whatever they call them. You instead have to pass the item you want the length of, into the len() function:

    return HttpResponse("There are articles " + len(arti))

or if you want to use format also:

    return HttpResponse("There are {} articles ".format(len(arti)))