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 trialBanjo Quint
1,452 PointsCode challenge with django
Can anyone advise me on this, why is it a bummer? Thanks for the help so far
from django.http import HttpResponse
# Write your views here
from .models import Article
def article_list(request):
articles = Article.objects.all()
article_len = len(articles)
return HttpResponse("There are " + article_len + "articles")
2 Answers
Cheo R
37,150 PointsNot sure why (maybe the regex they use to check answer), but I got it to pass keeping your code except, returning the string with format.
HttpResponse("There are {} articles".format(article_len))
Banjo Quint
1,452 Pointsusing format worked, thanks for all your efforts. PHP would have allowed it though!
csr13
33,293 Pointscsr13
33,293 PointsOk, I think this might answer your question.
You can do what has already been suggested -> using .format() as format converts to string.
return HttpResponse("There are {} articles.".format(len(articles)))
You can also do the conversion from int to string while concatenating.
return HttpResponse("There are " + str(article_len) + "articles.")
Or you can do :
return HttpResponse("There are s% articles." % ( len( articles ) ) )