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

Abe Daniels
PLUS
Abe Daniels
Courses Plus Student 2,781 Points

Need an extra set of eyes to look this over.

I am trying to create a new view and the error I am getting back is kinda vague.

Can someone be my bug splatter?

articles/views.py
#Now, create a view named article_list that selects all Article instances and returns an HttpResponse like "There are 5 articles." 
#Be sure to use the len() of the Article queryset to get the number of articles.

from django.http import HttpResponse

from .models import Article

def article_list(request):
    s = Article.objects.all()
    output = 'There are ' + len(s) + ' articles'
    return HttpResponse(output)

3 Answers

Django is probably complaining because you are trying to implicitly cast an int as a string.

You can use .format to fix your issue like so...

from django.http import HttpResponse

# Write your views here
from .models import Article

def article_list(request):
  s = Article.objects.all()
  output = 'There are {} articles'.format(len(s))
  return HttpResponse(output)
Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Correct, if updated with Ben Ackles comment below: "missing a period (.)"

Ryan, your solution does not work. Any ideas?

Ryan's solution works fine. The only problem is the string is missing a period (.) at the end. It's supposed to read "There are 5 articles."