Passing flask textbox value to an infinite while loop

Passing flask textbox value to an infinite while loop | Web Hosting Talk


‘);
var sidebar_align = ‘right’;
var content_container_margin = parseInt(‘350px’);
var sidebar_width = parseInt(‘330px’);
//–>









  1. Passing flask textbox value to an infinite while loop


    I’m running a flask server, with a textbox input and a while loop (in a different thread). I want to pass the input value from the textbox to the while loop.

    This is the .py code:

    Code:

    from flask import Flask, render_template, request
    import thread
    import time
    
    app = Flask(__name__)
    def main():
        
        while True:
            time.sleep(5)
            print "var = "+str(var)
    
    @app.route("/")
    def index():
        
        templateData = {
            'var': var 
    
        }
        return render_template('index.html', **templateData)
    
    @app.route('/', methods=('POST'))
    def post():
        
        global var 
        var = 0
        var = int(request.form('var'))
        return str("var: " + str(var))
        
    if __name__ == "__main__":
        thread.start_new_thread(main, ()) 
        thread.start_new_thread(post, ()) 
        app.run(host='0.0.0.0', port=8083, debug=True)

    This is the .html code:

    HTML Code:

    <!DOCTYPE html>
       <head>
          <title>POST</title>
       </head>
       <body>
        <form method="POST">
            var:<br>
            <input name="var">   
            <br><br>
            Current:    {{ var  }} <br><br>
            <input type="submit">
        </form>
       </body>
    </html>

    I don’t know what is the proper way to get the value to the while loop, because I’m getting mixed signals in the loop. If I for example write 3 in the textbox I’ll get…

    Code:

    var = 0
    var = 3
    var = 0
    var = 3
    var = 0
    var = 3
    var = 0
    var = 3

    …in the while loop, because it’s first reading var = 0 and then var = int(request.form(‘var’))













Similar Threads


  1. Replies: 0


    Last Post: 10-01-2012, 03:56 PM


  2. Replies: 8


    Last Post: 12-05-2005, 05:02 PM


  3. Replies: 9


    Last Post: 09-17-2005, 07:03 PM


  4. Replies: 0


    Last Post: 07-24-2001, 11:32 PM


  5. Replies: 0


    Last Post: 05-12-2001, 02:20 PM

Tags for this Thread



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  








DreamProxies - Cheapest USA Elite Private Proxies 100 Cheapest USA Private Proxies Buy 200 Cheap USA Private Proxies 400 Best Private Proxies Cheap 1000 USA Private Proxies 2000 USA Private Proxies 5000 Cheap USA Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive.com Proxies-free.com New Proxy Lists Every Day Proxies123.com Proxyti.com Buy Quality Private Proxies