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

Django 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

19,363 Points

Hey, 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."')

Thank you! Just a quick question, what is the 'f' after HttpResponse?

19,363 Points

Oh 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)))