0

Coming from Django I was used to the messages framework, where messages could be flashed to specific users and, up to a certaint point, used as a simple means of communication betwwen users. Is it possible in Flask with the flashing messages provided by the framework or do I have to write a messaging blueprint/app?

freethrow
  • 1,068
  • 3
  • 20
  • 34
  • There's the Message Flashing - http://flask.pocoo.org/docs/0.10/patterns/flashing/ – Henrik Andersson Nov 22 '14 at 18:43
  • 1
    Have you looked at http://stackoverflow.com/q/12232304/869951? You basically want a push mechanism, SSE is one, there are others. – Oliver Nov 22 '14 at 21:24
  • I am aware of the message flashing in Flask. What I need is the possibility for user A doing something (inviting user B to an event) and then message flashing for user B i.e. not to the one (A) making the actual request. – freethrow Nov 22 '14 at 22:55

1 Answers1

0

yeah you can use something like this app.py file

from flask import flash, Flask, render_template, methods

app = Flask(__name__)
app.secret_key = 'my_key_is_set_here'

@app.route('/')
def page():
   flash("write flash message here")
   return render_template('html_page.html')

if __name__ == "__main__":
   app.run(debug=True)

html_page.html file

{% with messages = get_flashed_messages() %}
    {% if messages %}
            {% for message in messages %}
                <div class="alert alert-danger alert-dismisable" role="alert">
                    <li>{{ message }}</li>
                </div>
            {% endfor%}
    {% endif %}
{% endwith %}

This code just outputs the message to the page, you can mess around with it but this is the simple setup

JayE
  • 91
  • 1
  • 1
  • 11