Flask, one flash message not getting displayed [duplicate]

Web Technologies Web Development 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating
_x000D_ _x000D_ _x000D_ This question already has an answer here:_x000D_ _x000D_ _x000D_ Flask flash message no longer works when using ajax_x000D_ _x000D_ 2 answers_x000D_ _x000D_ _x000D_ _x000D_ How to manage a redirect request after a jQuery Ajax call_x000D_ _x000D_ 31 answers_x000D_ _x000D_ _x000D_ _x000D_ _x000D_ I know flash is set up properly as all other flash messages are being displayed correctly. I have updated one view. It used to call the flask route from a javascript window.location function but now am using $.post() to send parameters to the route. The location of the flash call hasn't changed (I put a print statement just before it and that executes so I know the interpreter gets to the flash call). All code in the route's method executes correctly but the flash message does not show and I am at a loss. Nothing coming up from Google searches. Here are the last 3 lines in the route method db.session.commit() flash('Database Updated') return redirect(url_for('index'))

Posted on 16 Aug 2022, this text provides information on Web Development related to Web Technologies. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ I think (but I'm not sure, because you didn't include the code of index), that the template in index doesn't include the flash. You need to format the index page (or the base template) to display the flash. Check the examples in: http://flask.pocoo.org/docs/0.12/patterns/flashing/, practically: {% with messages = get_flashed_messages() %} {% if messages %}
    {% for message in messages %}
  • {{ message }}
  • {% endfor %}
{% endif %} {% endwith %}

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Important Web Technologies Links

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community