我有一个来自 Flask 应用程序的代码:
def getExchangeRates():
""" Here we have the function that will retrieve the latest rates from fixer.io """
rates = []
response = urlopen('http://data.fixer.io/api/latest?access_key=c2f5070ad78b0748111281f6475c0bdd')
data = response.read()
rdata = json.loads(data.decode(), parse_float=float)
rates_from_rdata = rdata.get('rates', {})
for rate_symbol in ['USD', 'GBP', 'HKD', 'AUD', 'JPY', 'SEK', 'NOK']:
try:
rates.append(rates_from_rdata[rate_symbol])
except KeyError:
logging.warning('rate for {} not found in rdata'.format(rate_symbol))
pass
return rates
@app.route("/" , methods=['GET', 'POST'])
def index():
rates = getExchangeRates()
return render_template('index.html',**locals())
例如,@app.route装饰器被urls.py文件替换,您在其中指定路由,但是现在,我如何使该methods=['GET', 'POST']行适应Django 方式?
我对此有点困惑,有什么想法吗?
炎炎设计
相关分类