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

I can't know why my answer is wrong?

Can I know why is my question considered wrong and how can I print the length of the instances retrieved from the database in the correct way?

articles/views.py
from django.http import HttpResponse
from .models import Article
def article_list(request):
    article= Article.objects.all()
    article=str(article)
    return HttpResponse("There are ",article.len(),  "articles ")

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! There are a couple of things going on here that are causing problems. First, you are not using the len() method correctly. To get the length of an iterable item you should be using len(item). Also, commas inside the parentheses for a method denote arguments and are not concatenation operators. It is not necessary to turn the number into a string. My advice is to try string interpolation. Even if your string worked in this fashion, it is still missing a space before "articles" and a full stop/period. This will result in the incorrect string format required by the challenge For example:

word = "Hello"
result = len(word)

print("The length of the word is {}.".format(result))

This would print out: The length of the word is 5.

Hope this helps, but let me know if you're still stuck! :sparkles:

Thank you Jennifer Nordell very much .. I have done it in the correct way .. Thanks again