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

Help With Task 2 First-App View Django

I am not sure how to go about solving this task. I've attached my attempt. I've gone back and watched the video multiple times, but the example used with the list comprehension for the course list doesn't seem to be doing the same thing. I'd love some pointers on what is wrong with my code.

articles/views.py
from django.http import HttpResponse
from .models import Article
# Write your views here
def article_list(request):
    output = "There are " + len(Article.objects.all())+ " articles."
    return HttpResponse(output)

# Write your views here

1 Answer

I think your only issue is that you are trying concatenate the strings with the int object that len() returns.

from django.http import HttpResponse

from .models import Article

# Write your views here
def article_list(request):
    count = len(Article.objects.all())
    message = "There are {} articles.".format(count)
    return HttpResponse(message)