Is it possible to check if a django message and contents exist before adding another message?
In my example I am peforming a try
- except
in a loop, and if an exception occurs I add a message, but I only want the message to appear once, not for each item in the loop:
for i in data:
# do something...
try:
# try to act upon something
except:
# failed action add a message
if not messages.?.contains("Error: Unable to perform action X")
messages.add_message(request, messages.ERROR, 'Error: Unable to perform action X')
pass