简体   繁体   中英

Showing a specific message using Django message framework

I am trying to only show one message, if it exists. I tried this but it isn't working:

In view:

   messages.success(request, "some message", extra_tags="account_activated")

In template:

    {% if messages %}
        {% for message in messages %}
            {% ifequal message.tag "account_activated" %}
                <p>{{ message }}</p>
            {% endifequal %}
        {% endfor %}
    {% endif %}

If I remove {% ifequal message.tag "account_activated" %} it works.

Please help.

First, it's message.tags and not message.tag . Second, message.tags will contain all of the tags for the message separated by spaces, and not just the extra_tags .

For your example, message.tags should equal 'account_activated success' .

See the source code here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM