Q:

What am I doing wrong with my function within this django view?

This should be easy...  I'm taking a course and the way this is structured the view.py file can stand alone for the purpose of this quiz - it's more like a challenge.  Ok, so the request is this:
"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."
As a point of reference, the first part works. Anyway, the view.py file looks like this (The first part is where I import Article... guess I don't need the render import.):   
from django.http import HttpResponse
from django.shortcuts import render

from .models import Article

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

I'm not sure if the len function and/or the str function should be chained like this or if they should wrap the objects.  I tried putting articles.len().str() and that didn't seem to work.
Thanks in advance for any help,
Bruce

A:

You can try this:
article_count = len(articles)
output = "There are {} articles.".format(article_count)

len is a function that you call on a object and the format method already calls the str method for you.

A:

Using .all() just to count the number of records introduces an unnecessary overhead: 

If you only need to determine the number of records in the set (and
  don’t need the actual objects), it’s much more efficient to handle a
  count at the database level using SQL’s SELECT COUNT(*). Django
  provides a count() method for precisely this reason.

Directly get the count from the database using .count():
articles_count = Article.objects.count()
output = "There are {} articles.".format(article_count)

This is a generally accepted way to count the records unless the record instances are actually needed, or, if there is a specific requirement, as in your case: 

Be sure to use the len() of the Article queryset to get the number of articles.

Taking into account how the problem was stated, @Andoni's answer should be accepted.

