我对django有一个问题,我从Html索引页面获取名称,然后我想要请求数据。之后,我想用gettin html名称访问该数据
from flask import Flask,render_template,request
import requests
api_key = "35c1fbfe2a35fd3aaf075e7394bf8855"
url = "http://data.fixer.io/api/latest?access_key="+api_key
app = Flask(__name__)
@app.route("/" , methods = ["GET","POST"])
def index():
if request.method == "POST":
firstCurrency = request.form.get("firstCurrency") # EURO
secondCurrency = request.form.get("secondCurrency") # TRY
amount = request.form.get("amount") #20
response = requests.get(url)
#app.logger.info(response)
infos = response.json
firstValue = infos["rates"][firstCurrency]
secondValue = infos["rates"][secondCurrency]
result = (secondValue / firstValue) * float(amount)
currencyInfo = dict()
currencyInfo["firstCurrency"] = firstCurrency
currencyInfo["secondCurrency"] = secondCurrency
currencyInfo["amount"] = amount
currencyInfo["result"] = result
#app.logger.info(infos)
return render_template("index.html",info = currencyInfo)
else:
return render_template("index.html")
if __name__ == "__main__":
app.run(debug = True)
ı这行有问题,为什么
^{} [readthedocs]是一个方法,您应该调用该方法以JSON blob形式读取数据:
相关问题 更多 >
编程相关推荐