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 trialMilos Trifunovic
2,801 PointsDjango Lengths and Counts Challenge - solution is not accepted
I can't pass third task in the challenge 'Lengths and Counts'. Not only my code is not accepted by the grader, but also I got the message that task 1 is not passing anymore.
<html>
<head>
<title>Ice Cream</title>
</head>
<body>
<div>We have {{ flavors.count }} flavors today.</div>
<ul>
{{% for flavor in flavors %}}
<li> {{ flavor.name }} </li>
{{% endfor %}}
</ul>
</body>
</html>
10 Answers
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Milos
I have just run it like so and it worked. On task 1 make sure there is no space between the template variable and the closing div. so for task 1 it should read as so
<div>{{flavors|length}}</div>
the rest of the html file should look like so
<html>
<head>
<title>Ice Cream</title>
</head>
<body>
<div>We have {{ flavors.count }} flavors today.</div>
<ul>
{% for flavor in flavors %}
<li>{{flavor}}</li>
{% endfor %}
</ul>
</body>
</html>
Chris Freeman
Treehouse Moderator 68,441 PointsExtra spaces within {{ }}
should not matter. Here is an alternate answer that uses unordered_list
filter:
<html>
<head>
<title>Ice Cream</title>
</head>
<body>
ā
{# Task 1: <div>We have {{ flavors|length }} flavors today.</div> #}
{# Task 2: #}
<div>We have {{ flavors.count }} flavors today.</div>
ā
<ul>
{# Task 3 #}
{{ flavors|unordered_list }}
</ul>
ā
</body>
</html>
The template tag {# #}
is used to mark Django comments. These do not show up in the rendered HTML page.
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Milos
All you need to do is print out the flavor.
<ul>
{% for flavor in flavors %}
<li> {{ flavor }} </li>
{% endfor %}
</ul>
Chris Freeman
Treehouse Moderator 68,441 PointsNote: the format {{% %}}
should be replaced with single curly bracket: {% %}
Andreas cormack
Python Web Development Techdegree Graduate 33,011 Pointsupps typo didnt see that
Kenneth Love
Treehouse Guest TeacherI can't get it to fail with {{flavor}}
. Let me know if it acts up again.
Milos Trifunovic
2,801 PointsThanks, but this isn't accepted by the graded either.
Milos Trifunovic
2,801 PointsThanks, it worked this time. Seems like leaving out spaces from "{{flavor}}" was crucial.
Milos Trifunovic
2,801 PointsSorry, I need to clerify, "{{flavor}}" passes but "{{ flavor }}" don't.
Chris Freeman
Treehouse Moderator 68,441 PointsMilos, can you post your complete failing code?
Milos Trifunovic
2,801 PointsChris, this is what didn't pass:
<html>
<head>
<title>Ice Cream</title>
</head>
<body>
<div>We have {{ flavors.count }} flavors today.</div>
<ul>
{% for flavor in flavors %}
<li>{{ flavor }}</li>
{% endfor %}
</ul>
</body>
</html>
Chris Freeman
Treehouse Moderator 68,441 PointsThis code, as written, passes for me for all 3 tasks. Can you try to re-run the challenge?
Milos Trifunovic
2,801 PointsOk, I think it was the indentation error that caused the code not to pass. In my previous post you can see, but just barely, that <li>{{ flavor }}</li> has one extra space before the characters, and I didn't notice that by now.
I should double check indentation in the future.
Kenneth Love
Treehouse Guest TeacherHmm, I've passed with {{flavor}}
, {{ flavor }}
(one space), and {{ flavor }}
(two spaces).
I'm wondering if there wasn't some other issue, maybe a timeout on our end or some other typo you fixed and forgot, that caused the issue.
Thanks for helping us explore this more, though.
Milos Trifunovic
2,801 PointsKenneth, I got back to the test to reproduce the error but I couldn't either. I thought it was indentation error but obviously it isn't. Must be some other error in my code that I overlooked, and not the grader fault.