Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 django 模板中,对于每个类别,我都会遍历每个子类别。但是如何对子类别进行排序?我需要它灵活,以便我可以选择我的排序。
{% for cat in categories %} {% for subcat in cat.subcategories_set.all%} {% endfor %} {% endfor %}
您可以使用dictsort模板标签,它可以让您按任何键进行排序。文档
dictsort
中的元素?