使用Django消息框架显示特定消息 [英] Showing a specific message using Django message framework
本文介绍了使用Django消息框架显示特定消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试仅显示一条消息(如果存在).我试过了,但是没用:
I am trying to only show one message, if it exists. I tried this but it isn't working:
视图中:
messages.success(request, "some message", extra_tags="account_activated")
在模板中:
{% if messages %}
{% for message in messages %}
{% ifequal message.tag "account_activated" %}
<p>{{ message }}</p>
{% endifequal %}
{% endfor %}
{% endif %}
如果我删除 {%ifequal message.tag"account_activated"%}
,则可以正常工作.
If I remove {% ifequal message.tag "account_activated" %}
it works.
请帮助.
推荐答案
首先,它是 message.tags
,而不是 message.tag
.其次, message.tags
将包含所有用空格分隔的消息标签,而不仅仅是 extra_tags
.
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
.
例如, message.tags
应该等于'account_activated success'
.
请参阅源代码 查看全文