Flask Flash Messages Blank - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Flask Flash Messages Blank (/thread-5694.html) |
Flask Flash Messages Blank - Leaf - Oct-16-2017 View.py @site.route('/dashboard/') def dashboard(): flash("flash test!!!!") flash("fladfasdfsaassh test!!!!") flash("asdfas asfsafs!!!!") return render_template("dashboard.html")dashboard.html {% with messages = get_flashed_messages() %} {% if messages %} <p> Message was validated and flashed from view, check list to see if successful: </p> <ul> {% for messages in messages %} <li>{{ message }}</li> {% endfor %} </ul> {% endif %} {% endwith %}This is what is printed: Message was validated and flashed from view, check list to see if successful: --- I first had the problem when I was trying to create a form using Form-WTF and Miguel Grinberg's tutorial. I thought maybe I was doing something wrong as the list was registering my flashes but printing them all blank, to test it I created dashboard.html and printed only flashes and received the same problem. I researched in as many different ways as I could flask/flash problems. But have not discovered the problem thus far. Someone suggested it could be a server issue; but I'm new to python and don't know how to check for server issues, nor do I know how to change the server name since I didn't set it. I did go to __init__.py and type SERVER_NAME = app.localhost as I read someone else said that worked for them; but this did not work for me. Note: In the original code I had tested return redirect. As someone said return redirect was their problem, while another said (when I researched the problem), that the server was their issue; and so for the former using return render_template fixed it as opposed to: "return redirect('/index')" So I tried render_template, and when that rendered blank I was out of ideas for how to solve. (just adding that information to show I've tried multiple solutions that I can think of based on the search engine but still drawing up well...blanks) RE: Flask Flash Messages Blank - buran - Oct-16-2017 didn't test it, but first fix line 8 in html file - you have messages twice. Should be {% for message in messages %}
RE: Flask Flash Messages Blank - Leaf - Oct-16-2017 Wow, something so simple; that fixed the problem; thank you so much! |