Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add flash_error and get_flashed_errors #301

Closed
Poincare opened this Issue · 4 comments

4 participants

Dhaivat Pandya Karol Kuczmarski Daniel Neuhäuser ThiefMaster
Dhaivat Pandya

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.

Karol Kuczmarski

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
Daniel Neuhäuser
Collaborator

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

Daniel Neuhäuser DasIch closed this
ThiefMaster

@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)!

Karol Kuczmarski

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
Something went wrong with that request. Please try again.