[Django]-Django: issue with unit-test ListView and assertContains

2👍

The “No polls are available” message is from the template. From part 3 of the tutorial:

{% if latest_poll_list %}
    <ul>
    {% for poll in latest_poll_list %}
        <li><a href="/polls/{{ poll.id }}/">{{ poll.question }}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}

You need to update your template rsvp_list.html to include “No persons are available.” in a similar way.

1👍

Previous answer works, but more effective way (you won’t be using redundant template constructions) to do that with the “for-empty” construction like this:

<ul> 
{% for poll in latest_poll_list %}
    <li><a href="/polls/{{ poll.id }}/">{{ poll.question }}</a></li>
{% empty %}
    <li>No polls are available.</li> 
{% endfor %} 
</ul>

Leave a comment