function flash() not working with redirect()
See original GitHub issueHere’s the example:
from flask import Flask, flash, get_flashed_messages, redirect, url_for
app = Flask(__name__)
app.secret_key = 'some_secret'
@app.route('/')
def index():
app.logger.debug(get_flashed_messages())
return 'Hello world'
@app.route('/generate/success')
def page_success():
flash('This message will be visible!')
return str(get_flashed_messages())
@app.route('/generate/fail',)
def page_fail():
flash('This message will be lost!')
return redirect(url_for('index'))
if __name__ == "__main__":
app.run()
As you can see flash() fails when using redirect. Tried with SERVER_NAME
both set and unset. Using Flask==0.10.1
.
Please resolve the issue ASAP since it’s a top blocker in my project.
Issue Analytics
- State:
- Created 9 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Session flash message not working after redirect route
I have problem with session flash message working. I have function store: public function store( Request $request ){ $book = new \App\Book( $request->all()...
Read more >Laravel flash message and redirection not working properly
The controller should return the redirect, not the check permission. Try to return what check permission is returning in the controller.
Read more >Setting flash message with $this->Flash is not working
$this->Flash->render() ?> In the index function of a controller I set a flash message as: $this->Flash->error(('Flash error message.');
Read more >Flash messages from Laravel not shown in Inertia after ...
It seems to work fine until I do a Redirect::route('auth.index')->with([...]) Then the success or error message won't fire at all. Works fine if ......
Read more >Flash Messages | Laravel Livewire
In cases where it's useful to "flash" a success or failure message to the user, ... 9 public function update() ... 9 return...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Okay, I got it. The issue was caused by setting
APPLICATION_ROOT
which is discouraged in the Wiki so the fault was undoubtedly on my side. Sorry for bothering you. I’m gonna close this issue now.I am having the same issue and I don’t have an APPLICATION_ROOT in my project. After flashing a message, if I
return redirect('/ ')
the message doesn’t appear on the redirected page but if I comment out the redirect and usereturn render_template("index.html")
the message does display.Setting cache timeout to 0 “fixes” this but this site relies on caching for performance reasons so if there is some way to get message flashing to work on redirect and WITH caching enabled, please let me know. Thanks!!