Displaying Django Messages Framework Messages

前端 未结 6 574
野趣味
野趣味 2021-01-04 07:12

I have been using the Django Messaging Framework to display messages to a user in the template.

I am outputting them to the template like this:



        
6条回答
  •  旧巷少年郎
    2021-01-04 08:02

    Of course you can do it with {% regroup %} tag but you have to use dictsort filter aswell if you want to work properly. So firstly, tags should be sort by name and then group:

    {% if messages %}
        {% regroup messages|dictsort:"tags" by tags as message_list  %}
    
        {% for tags in message_list %}
            
      {% for message in tags.list %}
    • {{ message }}
    • {% endfor %}
    {% endfor %} {% endif %}

提交回复
热议问题