vendredi 22 décembre 2017

How to utilize bootstrap toggle with flask

This question is an extension of this question regarding using the Bootstrap toggle with flask.

My code for the toggle is as follows:

<div class='media'>
                <div class='media-left'>
                  <div class='media-object'>
                    <div class='padding-right'>
                      <form action="/menu" method="post">
                        <input name="toggle" onclick="this.form.submit()" data-off="&lt;i class='fa fa-times'&gt;&lt;/i&gt; " data-on="&lt;i class='fa fa-check'&gt;&lt;/i&gt; " data-onstyle='success' data-size='large' data-style='ios' data-toggle='toggle' id='activate-toggle' type='checkbox' value="on">
                        <input name="toggle" type="hidden" value="off">
                      </form>
                    </div>
                  </div>
                </div>
                <div class='media-body'>
                  <div id='console-event'></div>
                </div>
              </div>

And my endpoint for the page is as follows:

    @app.route('/menu', methods=['POST', 'GET'])
def get_callback():
    if request.method == 'POST':
        button = request.form['toggle']
        print(button)
    return render_template('dashboard.html')

However I am not able to get any response from my button.

I am very lost at this point. I have tried to copy the format of the question above however I still cannot get the button to print or even use the POST method.

Here are my questions:

  1. How can I get a response from my button?
  2. How do I save the orientation so that when the user logs back in the button is how they previously left it?

(I am using SQLAlchemy if this is of any importance.)

Any help would be greatly appreciated!

Thank you,

Jonah




Aucun commentaire:

Enregistrer un commentaire