mardi 31 octobre 2017

show dynamically changing data in my web app by flask

i want to show some dynamically changing data from request api on my web app my request is :

 url='http://ift.tt/2hrSIVr'
  z=[]
  r = requests.get(url)
  x=r.json()
  e1=x['result'][0]['Ask']

i want to display it on web app in pythonanywhere i have html file like this :

<!DOCTYPE html>

<html>

<head>
    <title>aaa</title>
</head>

<body>

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

<div id="aaa"></div>

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

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

    $.ajax({
      url: "/aaa",
      type: "get",
      data: {jsdata: text},
      success: function(response) {
        $("#aaa").html(response);
      },
      error: function(xhr) {

      }
    });
});
</script>

</body>

</html>

my flask file:

from flask import Flask, render_template, request
import requests


app = Flask(__name__)


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/aaa')
def aaa():
    text = request.args.get('jsdata')

    aaa_list = []

    if text:
         url='http://ift.tt/2hrSIVr'
         z=[]
         r = requests.get(url)
         x=r.json()
         e1=x['result'][0]['Ask']
         suggestion=e1
         for suggestion in aaa:
            aaa_list.append(suggestion.attrs['data'])

        #print(aaa_list)

    return render_template('aaa.html', aaa=aaa_list)


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

i get this error :

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

i think something with ajax. please help me. I have no idea how to fix it and how to update data from http://ift.tt/2hrSIVr dinamicly changing every 2-3 seconds for example




Aucun commentaire:

Enregistrer un commentaire