Hello everyone! I hope this video has helped solve your questions and issues. This video is shared because a solution has been found for the question/problem. I create videos for questions that have solutions. If you have any other issues, feel free to reach out to me on Instagram: / ky.emrah
Below, you can find the text related to the question/problem. In the video, the question will be presented first, followed by the answers. If the video moves too fast, feel free to pause and review the answers. If you need more detailed information, you can find the necessary sources and links at the bottom of this description. I hope this video has been helpful, and even if it doesn't directly solve your problem, it will guide you to the source of the solution. I'd appreciate it if you like the video and subscribe to my channel!How do I markup a flash message in Flask?
I was running a Flask application using Python 3.9.13, Flask 1.1.2, Jinja2 2.11.3, and MarkupSafe 1.1.1, using a Redis (3.5.3) as my session store. When I created a flash message with
flash(Markup(' b This /b is a b WARNING /b .'),category="warning")
flash(Markup(' b This /b is a b WARNING /b .'),category="warning")
Flask would display (as expected)
This is a WARNING.
This
WARNING
with the selected backbrouund color associated with the warning flash messages.
warning
I'm trying to move the application to Python 3.12.4, Flask 3.0.3, and MarkupSafe 2.1.5 (Jinja2 ia at 3.1.4, but Flask moved to use MarkupSafe directly, instead of importing it from Jinja2, so I don't think that's relevant, Redis is 5.0.8). However, when I try to redirect to a page with that set as the flash message, the app fails sliently with an Internal Server Error.
Digging deeply into Flask, I can see that it's throwing an exception Encoding objects of type Markup is unsupported, when it's handling the process_response and trying to save the session https://github.com/pallets/flask/blob..., and it seems to be caused by the Markup object in the _flashes list. If convert the Markup to a string, it doesn't fail, but the message is displayed as:
Encoding objects of type Markup is unsupported
https://github.com/pallets/flask/blob... b This /b is a b WARNING /b . (It does display with the correct background color.)
b This /b is a b WARNING /b .
Is there a way to format a flash message in the current Flask like we used to be able to do in earlier versions, or am I doing something wrong?
Tags: python,flask,flash,markupSource of the question:
https://stackoverflow.com/questions/7...
Question and source license information:
https://meta.stackexchange.com/help/l...
https://stackoverflow.com/
Информация по комментариям в разработке