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 trialArthur Kakulidis
2,657 PointsDjango Basics
I need help with this exercise. I also don't really know what I'm doing here. Someone please help, Thank you!
from django.http import HttpResponse
from .models import Article
# Write your views here
def article_list(request):
articles = Article.objects.all()
output =
return HttpResponse('There are' articles.len() 'articles')
2 Answers
diogorferreira
19,363 PointsHey, you're nearly there, but in this case you don't need an extra output variable, Kenneth only does that in the video because he wants to return a list of the items not the amount that they have.
- You'd just need to use len() on articles like this:
len(articles)
- When you concatenated the string you also forgot the commas separating the string and variable I decided to use a f-string but you don't need to.
This is my example if you need any more help.
def article_list(request):
articles = Article.objects.all()
return HttpResponse(f'"There are {len(articles)} articles."')
diogorferreira
19,363 PointsOh thatβs an f string itβs just another way to format it, you can use .format() aswell but I prefer f-strings I find them to be cleaner and easier to read when you have more than 4 variables.
This is how youβd use .format()
return HttpResponse('"There are {} articles.β.format(len(articles)))
Arthur Kakulidis
2,657 PointsArthur Kakulidis
2,657 PointsThank you! Just a quick question, what is the 'f' after HttpResponse?