Displaying Django Messages Framework Messages

前端 未结 6 578
野趣味
野趣味 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 07:53

    I managed with template tags only:

    {% if messages %}
        {% regroup messages by tags as messages %}
        
    {% for tags in messages %}
      {% for message in tags.list %}
    • {{ message|capfirst }}
    • {% endfor %}
    {% endfor %}
    {% endif %}

    The key is the {% regroup %} tag.

    This still has an some issues because the tags attribute includes the extra_tags of the message so if you make use of it you will get additional

      groups.

      In future versions (probably 1.7), there will be a level_tag attribute so that issue will be gone soon.


      (As soon as the level_tag attribute is available)

      {% if messages %}
          {% regroup messages by level_tag as messages %}
          
      {% for level in messages %}
        {% for message in level.list %}
      • {{ message|capfirst }}
      • {% endfor %}
      {% endfor %}
      {% endif %}

提交回复
热议问题