I want to flash a message with a variable in flask. Can anyone tell me how can i do so. For example:
a = 3
flash("message A message continues")
I want to achieve this.
CodePudding user response:
You will need to insert your variable into the string that you give to flash().
There are different ways to achieve this:
a = 3
message = "message {} message continues".format(a) # Using the format method
message = f"message {a} message continues" # Using f-strings (Python >= 3.6)
message = "message %d message continues" % (a) # % Formatting
message = "message " str(a) " message continues" # Concatenation
flash(message)