gpt4 book ai didi

django - 模板中没有命名循环。 'row1,row2' 未定义

转载 作者:行者123 更新时间:2023-12-02 07:17:14 26 4
gpt4 key购买 nike

在我的 django 内联表单集中,表单 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 %}

当我尝试打开表单时,它给出了

/profile/add/处的模板语法错误模板中没有命名循环。 “row1,row2”未定义

如何避免此错误?

最佳答案

这不是您使用该标签的方式,如 the docs展示。这些值应该用空格而不是逗号分隔,如果它们是文字字符串,则应该用引号引起来。

{% cycle "row1" "row2" %} 

关于django - 模板中没有命名循环。 'row1,row2' 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40603961/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com