vendredi 3 novembre 2017

Show data from request on flask app

I want to show data from request http://ift.tt/2hrSIVr' on my web app. i want this data to update on my app lets say every 3 seconds. I am using flask 3.6 and python 3.6. My flask.py file :

from flask import Flask, render_template, request
import requests



app = Flask(__name__)


@app.route('/', methods=['GET', 'POST'])
def price():
     url='http://ift.tt/2hrSIVr'
     z=[]
     r = requests.get(url)
     x=r.json()
     e1=x['result'][0]['Ask']
     e2=x['result'][0]['Bid']
     z.append(e1)
     z.append(e2)
     #print("TEMPLATE_FOLDER = {}".format(app.template_folder))
     return render_template('templ.html', data=z ,template_folder='/home/...templates/')




if __name__ == '__main__':
    app.run(debug=True)

this is my templ.html:

<!DOCTYPE html>

<html>

<head>
    <title>Suggestions</title>
</head>

<body>

Search: <input type="text" id="search_form_input"></input>

<div id="place_for_suggestions"></div>

<script src="http://ift.tt/2eBd7UN"></script>

<script>
$("#search_form_input").keyup(function(){
    var text = $(this).val();

    $.ajax({
      url: "/",
      type: "get",
      data: <label id="value_lable">
        
        </label>,
      success: function(response) {
        $("#place_for_suggestions").html(response);
      },
      error: function(xhr) {
        //Do Something to handle error
      }
    });
});
</script>

</body>

</html>

i got web site without currency price data -http://ift.tt/2xXvuN1

i am new in flask , please help me. What should i do to show data from request on my site? how to updatw it every 3 sec?




Aucun commentaire:

Enregistrer un commentaire