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

Utkarsh Gupta
Utkarsh Gupta
546 Points

Everything is correct. Why it ain't working?

I just can't find out what is wrong with the solution I have written.

articles/views.py
from django.http import HttpResponse
from .models import Article
# Write your views here

def article_list(requests):
   articles = Article.objects.all()
   count = len(articles)
   return HttpResponse("There are " + count + " articles.")

1 Answer

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

Hi there! You're doing very well so far. But count is an integer. And it needs to be a string to be concatenated. So here you have two choices to solve this challenge. You can either convert the value in count to a string and use concatenation, or you can leave it as it is and use interpolation.

Using interpolation:

count = len(articles)
return HttpResponse("There are {count} articles.")

Using concatenation:

count = str(len(articles))
return HttpResponse("There are " + count + " articles.")

Note that I've listed them in order of my personal preference. Hope this helps! :sparkles:

Utkarsh Gupta
Utkarsh Gupta
546 Points

Thanks a lot, Jennifer! :) It worked. But I had read somewhere that we can concatenate strings and int in Python due to polymorphism. Is that a feature of version other than python3 only? Or, Do I need to correct my knowledge?