Django“方法”对象不可下标

时间:2020-10-18 19:44:38

标签: python python-requests

我对django有问题,我从HTML索引页面获取名称,之后我想请求数据。然后,我想使用gettin html名称访问该数据。

let defaultLayers = this.platform.createDefaultLayers();
let map = new H.Map(
    this.mapElement.nativeElement,
    defaultLayers.vector.normal.map,
    {
        zoom: 10,
        center: { lat: this.lat, lng: this.lng },
        renderBaseBackground: {lower: 2, higher: 2}
    }
);
map.getViewModel().setLookAtData({
    tilt: 30
});        
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
var ui = H.ui.UI.createDefault(map, defaultLayers);
map.addLayer(new H.map.layer.Layer({
    min: 3,
    max: 7
}));

ı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) 这行有问题,为什么?

1 个答案:

答案 0 :(得分:0)

.json(…) [readthedocs]方法,您应该调用将数据读取为JSON blob的方法:

infos = response.json()  # ←  call the method