Whenever I POST a form, I display error messages. However, the way I add flashes to the queue, some messages stay after I POST to the form, and some don’t. I noticed that it’s due to the way I add messages to the queue.
The regular way that works perfectly:
post_data = request.POST
if 'submit' in post_data:
... function(post_data) ...
if ...:
request.session.flash(u'This is some error message')
request.session.flash(u'Maybe some other error message')
And in the mako file:
<html>...<body>...
% for m in request.session.pop_flash():
<div class="alert-message">
<p>${m}</p>
</div>
% endfor
...</body></html>
However, the way I want some of the messages to work is:
if 'submit' in post_data:
messages = function(...) # output is always a list
for m in messages:
request.session.flash(m)
When I do that, every time I rePOST to the same form, ALL the previous messages are added to the .flash() again. Thus, the error messages just keep piling. How do I fix this or work around this?
I figured out the problem, but I’m not sure why it happened. Before, I initiated
messageas a keyword:I believe that after each POST,
messagedidn’t clear even though I never calledvalidate()with it. However, when I removedmesssageas a keyword, it works fine:Anyone know why this is the case?