Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask Flash Messages Blank
#1
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)
Reply
#2
didn't test it, but first fix line 8 in html file - you have messages twice. Should be {% for message in messages %}
Reply
#3
Wow, something so simple; that fixed the problem; thank you so much!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  enable flash using selenium chromedriver Fre3k 1 4,248 Nov-27-2020, 12:15 PM
Last Post: JellyCreeper6
  Django or Flash for a would be freelancer? davinci 2 4,641 Jul-21-2017, 07:03 PM
Last Post: nilamo
  Selenium and Flash ATXpython 3 8,668 Oct-10-2016, 09:52 PM
Last Post: ATXpython

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020