Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to flash message with variables in Flask

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading