djangosnippets.org: Latest snippets posted by io_errorhttps://djangosnippets.org/users/io_error/2008-06-15T12:09:13.564668-05:00io_errorTemplatetag startswith + message tuned
2008-06-15T12:09:13.564668-05:00io_errorhttps://djangosnippets.org/snippets/806/<p>Template:</p>
<pre><code> `<div id="messageBox_{{ forloop.counter0 }}" style="border:1px solid #ccc;background-color:white" onclick="document.getElementById ('messageBox_{{ forloop.counter0 }}').style.display = 'none';">
{% ifstartswith message "#ok#" %}
<font color="green">
{% endifstartswith %}
{% ifstartswith message "#error#" %}
<font color="red">
{% endifstartswith %}
{{ message|cut:"#ok#"|cut:"#error#" }}
</font>
</div>`
</code></pre>
<p>In a view you can now do something like that:
<code>request.user.message_set.create(message="#ok#Hello …</code></p>
Freely redistributable