0

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'))
Philip Butler
  • 479
  • 1
  • 5
  • 13

1 Answers1

3

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 %}
    <ul class=flashes>
    {% for message in messages %}
      <li>{{ message }}</li>
    {% endfor %}
    </ul>
  {% endif %}
{% endwith %}
Giacomo Catenazzi
  • 8,519
  • 2
  • 24
  • 32
  • Hey. No I have included it. As said above, it works for every other flash message (the code above is in the base.html file which is included for all templates. Other flash messages display correctly on the index page) But for some reason, just this particular one is getting lost somewhere – Philip Butler Feb 27 '18 at 15:49
  • Do you use flash with priority on the other cases? – Giacomo Catenazzi Feb 27 '18 at 15:52
  • every other flash() call the program uses matches the example above in every way apart from the display string parameter – Philip Butler Feb 27 '18 at 15:53
  • so it should print flash like the other cases. I think it is just a stupid error (a typo or something like that), but without full code, I cannot help. Check the debug log. Try to move the flash at the beginning of function (is db.commit raising an exception?). All dispatches are on the same file? (flask is weak on multiple file) – Giacomo Catenazzi Feb 27 '18 at 15:59
  • checking the debug now and the message is being passed to helpers.py and is recorded correctly. I really have no idea what is happening. Anyway thanks for your time – Philip Butler Feb 27 '18 at 16:01