1

我正在尝试使用模板影响项目列表,{% with %}{% endwith %}但在我的变量中仍然一无所获这是代码

{% for item in data %}
    <tr>    
    {% with value = item.user_id %}
    {% endwith %}   
<td><a href="{% url accounts value %}"><center>{{ item.Company_name }}</center></a></td>

我得到这个错误

NoReverseMatch at /filter/

Reverse for '' with arguments '('',)' and keyword arguments '{}' not found.
4

2 回答 2

1

如下移动{%endwith%}after</td>标签。

{% for item in data %}
        <tr>    
          {% with value = item.user_id %}

              <td><a href="{% url accounts value %}"><center>{{ item.Company_name }}</center>
              </a></td>

          {% endwith %}

使用定义的变量范围with仅在with块内。

于 2013-05-16T11:38:45.753 回答
1

您应该将视图名称放在引号中:

{% url "accounts" value %}
于 2013-05-16T11:48:45.197 回答