2

I have problem with flask flash() function, get_flashed_messages() always returns me duplicates. I set flash for logout :

@app.route('/logout')
def logout():
    session.pop('logged_in', None)
    flash('You are logged out!', 'success')
    return redirect(url_for('home'))

and in view I have:

{% with messages = get_flashed_messages(with_categories=true) %}
    {% if messages %}
        {% for type, message in messages %}
            <div class="callout {{ type }}">
                {{ message }}
            </div>
        {% endfor %}
    {% endif %}
{% endwith %}

Is it a flask bug? I have printed messages variable and this have more than 1 flash logout message, the count of messages is in range 1-3.

user3501587
  • 425
  • 5
  • 16
  • 1
    Are you sure you aren't accidentally sending multiple requests? Could you give us the output from running the Flask application? – Jack Evans Dec 23 '16 at 10:52
  • You mean html?? – user3501587 Dec 23 '16 at 11:05
  • 1
    The log from debug=True in your console after running `python .py`. You want to look out for any duplicate `GET` requests after refreshing your browser, as they'll probably be what's triggering the duplicate messages. It's most likely a missing resource, see related http://stackoverflow.com/questions/17240394/flask-getting-random-repeated-flash-messages-when-flash-is-in-app-before-req – Jack Evans Dec 23 '16 at 11:07
  • Here is log, for the fifth time it is doubly http://snipet.co.uk/Qi/raw – user3501587 Dec 23 '16 at 11:33
  • Do you use some sort of layout.html as as a base template? – Stijn Diependaele Dec 23 '16 at 12:39
  • @StijnDiependaele yes, i use layout.html as base template, and [this](http://snipet.co.uk/uj/raw) is in layout.html – user3501587 Dec 23 '16 at 13:03

0 Answers0