Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django重组列表_Python_Django - Fatal编程技术网

Python Django重组列表

Python Django重组列表,python,django,Python,Django,我在Django有一个问题。 情况是:我有一个dictionary by views.py,我需要执行以下操作: Box A_name: 1 section: 1.1 element 1 ... 1.n element n N section: N.1 element ... N.m element Box B_name: ... html中的代码是: {% load get_boxfilter %} {% regroup all_boxes|dictsort:"box_type" by

我在Django有一个问题。 情况是:我有一个dictionary by views.py,我需要执行以下操作:

Box A_name:
1 section:
1.1 element 1
...
1.n element n

N section:
N.1 element
...
N.m element

Box B_name:
...
html中的代码是:

{% load get_boxfilter %}
{% regroup all_boxes|dictsort:"box_type" by box_type as type %}

<ul>
{% for pos in type %}
    <li> Box {{ pos.grouper|get_boxfilter }}
    <ul>
        {% for item in pos.list %}

          <li> element {{ item.name }} section {{ item.section }}</li>
        {% endfor %}
    </ul>
    </li>
{% endfor %}
</ul>
它通过框名称重新组合:

Box A_name:
1. element 1 section 1
2. element 2 section 2
3. element 3 section 1
Box B_name:
...
但是如何按“节”(int值)分组呢


谢谢

为什么不按部分重新组合呢

{% load get_boxfilter %}
{% regroup all_boxes by section as type %}

<ul>
{% for pos in type %}
    <li> Box {{ pos.type|get_boxfilter }}
    <ol style="list-style-type: decimal">
         <li>{{ pos.grouper }}</li>
         <ol style="list-style-type: decimal">
             {% for item in pos.list %}
                 <li> element {{ item.name }}</li>
             {% endfor %}
         </ol>
    </ol>
    </li>
{% endfor %}
</ul>
{%load get_boxfilter%}
{%按节将所有_框重新组合为类型%}
    {%类型中的pos为%}
  • 框{pos.type | get_boxfilter}
  • {{pos.gropper}}
  • {pos.list%中项目的%s}
  • 元素{item.name}
  • {%endfor%} {%endfor%}

为什么不按部分重新组合

{% load get_boxfilter %}
{% regroup all_boxes by section as type %}

<ul>
{% for pos in type %}
    <li> Box {{ pos.type|get_boxfilter }}
    <ol style="list-style-type: decimal">
         <li>{{ pos.grouper }}</li>
         <ol style="list-style-type: decimal">
             {% for item in pos.list %}
                 <li> element {{ item.name }}</li>
             {% endfor %}
         </ol>
    </ol>
    </li>
{% endfor %}
</ul>
{%load get_boxfilter%}
{%按节将所有_框重新组合为类型%}
    {%类型中的pos为%}
  • 框{pos.type | get_boxfilter}
  • {{pos.gropper}}
  • {pos.list%中项目的%s}
  • 元素{item.name}
  • {%endfor%} {%endfor%}

您还可以发布词典内容吗。这将有助于给你准确的答案。谢谢“id”,“姓名”,“章节”,“方框类型”请检查我的最新答案。你也可以发布字典内容。这将有助于给你准确的答案。谢谢“id”、“姓名”、“章节”、“方框类型”请检查我的最新答案我还没有测试过。请测试并让我知道是否有任何问题。也不确定是否需要按类型重新分组。取决于您的要求。
  • 框{{pos.type | get_boxfilter}}
  • 处的值错误:以10为基数的int()的文本无效。我假定错误是由
    get_boxfilter
    引起的。您能否通过在功能开始时打印
    print value
    来检查过滤器接收到的值。为什么需要
    get\u boxfilter
    偶数。请尝试在不使用筛选器的情况下测试我的代码。我尚未测试它。请测试并让我知道是否有任何问题。也不确定是否需要按类型重新分组。取决于您的要求。
  • 框{{pos.type | get_boxfilter}}
  • 处的值错误:以10为基数的int()的文本无效。我假定错误是由
    get_boxfilter
    引起的。您能否通过在功能开始时打印
    print value
    来检查过滤器接收到的值。为什么需要
    get\u boxfilter
    偶数。请尝试在不使用筛选器的情况下测试我的代码。
    {% load get_boxfilter %}
    {% regroup all_boxes by section as type %}
    
    <ul>
    {% for pos in type %}
        <li> Box {{ pos.type|get_boxfilter }}
        <ol style="list-style-type: decimal">
             <li>{{ pos.grouper }}</li>
             <ol style="list-style-type: decimal">
                 {% for item in pos.list %}
                     <li> element {{ item.name }}</li>
                 {% endfor %}
             </ol>
        </ol>
        </li>
    {% endfor %}
    </ul>