question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

function flash() not working with redirect()

See original GitHub issue

Here’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:closed
  • Created 9 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
robin92commented, Sep 4, 2014

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.

3reactions
karissamecommented, Jul 10, 2017

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 use return 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!!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found