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 Customizing Django Templates Template Tags and Filters Lengths and Counts

Milos Trifunovic
Milos Trifunovic
2,801 Points

Django 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.

ice_cream/templates/ice_cream/list.html
<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

Hi 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
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Extra 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.

Hi Milos

All you need to do is print out the flavor.

        <ul>
            {% for flavor in flavors %}
            <li> {{ flavor }} </li>
            {% endfor %}
        </ul>
Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Note: the format {{% %}} should be replaced with single curly bracket: {% %}

upps typo didnt see that

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

I can't get it to fail with {{flavor}}. Let me know if it acts up again.

Milos Trifunovic
Milos Trifunovic
2,801 Points

Thanks, but this isn't accepted by the graded either.

Milos Trifunovic
Milos Trifunovic
2,801 Points

Thanks, it worked this time. Seems like leaving out spaces from "{{flavor}}" was crucial.

Milos Trifunovic
Milos Trifunovic
2,801 Points

Sorry, I need to clerify, "{{flavor}}" passes but "{{ flavor }}" don't.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,423 Points

Milos, can you post your complete failing code?

Milos Trifunovic
Milos Trifunovic
2,801 Points

Chris, 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
Chris Freeman
Treehouse Moderator 68,423 Points

This code, as written, passes for me for all 3 tasks. Can you try to re-run the challenge?

Milos Trifunovic
Milos Trifunovic
2,801 Points

Ok, 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
Kenneth Love
Treehouse Guest Teacher

Hmm, 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
Milos Trifunovic
2,801 Points

Kenneth, 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.