Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No named cycles in template. 'row1,row2' is not defined

In my django inline formset, form html:

{% block body %}        
    <h2>Profile</h2>
    <hr>
    <div class="col-md-4">
        <form action="" method="post">{% csrf_token %}
            {{ form.as_p }}

            <table class="table">
                {{ familymembers.management_form }}

                {% for form in familymembers.forms %}
                    {% if forloop.first %}
                        <thead>
                        <tr>
                            {% for field in form.visible_fields %}
                                <th>{{ field.label|capfirst }}</th>
                            {% endfor %}
                        </tr>
                        </thead>
                    {% endif %}
                    <tr class="{% cycle row1,row2 %} formset_row">
                        {% for field in form.visible_fields %}
                            <td>
                                {# Include the hidden fields in the form #}
                                {% if forloop.first %}
                                    {% for hidden in form.hidden_fields %}
                                        {{ hidden }}
                                    {% endfor %}
                                {% endif %}
                                {{ field.errors.as_ul }}
                                {{ field }}
                            </td>
                        {% endfor %}
                    </tr>
                {% endfor %}
            </table>
            <input type="submit" value="Save"/> <a href="{% url 'profile-list' %}">back to the list</a>
        </form>
    </div>
{% endblock %}

When I tried to open form it gives

TemplateSyntaxError at /profile/add/ No named cycles in template. 'row1,row2' is not defined

How could I avoid this error?

like image 289
dj pro Avatar asked Mar 11 '23 16:03

dj pro


2 Answers

That's not how you use that tag, as the docs show. The values should be separated by spaces, not commas, and if they are literal strings they should be in quotes.

{% cycle "row1" "row2" %} 
like image 88
Daniel Roseman Avatar answered Mar 13 '23 04:03

Daniel Roseman


If you still get an error, you can try:

class="{% cycle 'row1' 'row2' %} formset_row"
like image 34
Juan Carlos Avatar answered Mar 13 '23 06:03

Juan Carlos