Add flash_error and get_flashed_errors #301

Closed
Poincare opened this Issue Aug 11, 2011 · 4 comments

Projects

None yet

4 participants

@Poincare

I think it would be convenient if we could have a flash_error and get_flashed_errors (I don't know if this is to be included in Jinja, or here) method, because its quite a pain to filter through the categories every time, especially when the messages and errors must be on different parts of the page.

If you guys do approve, I would like to be able to write the code for solving the issue, if you don't mind.

@Xion
Contributor
Xion commented Mar 3, 2013

Since 0.9, this seems easy to solve purely on the application side:

from flask import flash, get_flashed_messages
from yourapplication import app

flash_error = lambda message: flash(message, 'error')

get_flashed_errors = lambda: get_flashed_messages(category_filter=['error'])
app.jinja_env.globals['get_flashed_errors'] = get_flashed_errors
@DasIch
Contributor
DasIch commented Jul 27, 2014

With the category_filter parameter this would introduce an unnecessary special case.

@DasIch DasIch closed this Jul 27, 2014
@ThiefMaster
Member

@Xion: Careful, get_flashed_messages clears all flashed messages, even if you only retrieve a single category (it probably assumes that you retrieve the others during the same request)!

@Xion
Contributor
Xion commented Jul 27, 2014

It's not really get_flashed_messages doing it. It's just that flash messages don't persist beyond the next request, regardless if you display them all not.

I assumed this is known. Although docs for get_flashed_messages hint at the fact only indirectly ("This [category_filter] allows rendering categories in separate html blocks"), the short tutorial they reference makes it pretty clear the messages are not persistent in any shape or form.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment