Adding custom data calculation
Now let’s do more data calculation.
We open “process_data.py” and edit the file with this script:
def calculate_coin(price_usd): return (float(price_usd) > 40 def process(): data = get_data("/v1/ticker/?limit=10") all_coins = [] for coin in data: coin ["isover40"] = calculate_coin(coin["price_usd"]) all_coins.append(coin) return all_coins
Creating Bootstrap form and submit button
In this part we are going to cover creative form. We can go to the Bootstrap webpage and browse some forms available. The intention is, we are going to create a form request in some text and also create a button. Once
Edit your html code and this part in there:
<div class="row"> <div class="col-md-4"> <form class="form-line" method="post"> <div class="form-group"> <label>Enter coin: </label> <input type="text" class="form-control" id="cointype" \ placeholder="Coin here"> </div> <button type="submit" class"btn btn- default">Submit</button> </form> </div> </div>
Begin POST Process
Now is where it happens where we are going to create a POST request.
We have to open “app.py” and add the POST request
from flask import Flask from flask import render_template app = Flask(__name__) @app.route("/"), methods=['GET', 'POST'] def index (): if request.method == 'POST': return request.form['cointype'] elif request.method == 'GET': return render_template("index.html", data=process_data.process(), process_coin=process_data.process_coin()) if __name__ == "__main__": app.run(debug=True)