我试图返回API上36种产品的价格,这些价格是浮动值。 下面是我试图从中获取值的产品:https://pastebin.com/4k1rif6h (如果您需要访问API,请检查下面的内容,这可能是必需的)
当我试图将浮点值返回到HTML时,我遇到了一个错误:TypeError:“float”对象不可编辑(我已经阅读了有关该问题的线程,但它对我没有帮助)
以下是我的python代码:
@app.route('/bresell')
def reSell():
f = requests.get(
'https://api.hypixel.net/skyblock/bazaar?key=[tell me if key will be needed for helping]').json()
for x in npc_products:
sellPriceNPC = f["products"][x]["sell_summary"][0]["pricePerUnit"]
return render_template('resell.html', sellPriceNPC=sellPriceNPC)
下面是我在HTML上所做的工作:
<tbody>
<tr>
<td>temp</td>
<td>temp</td>
{% for sellFor in sellPriceNPC %}
<td>{{ sellFor }}</td>
{% endfor %}
</tr>
</tbody>
您试图在
sellPriceNPC
(thefor sellFor in sellPriceNPC
)上迭代,但它不是一个iterable(它不是一个列表),因为您将每个浮点值直接分配给它:相反,您希望保留一个列表并附加到该列表:
这样,您就可以正确地迭代列表并自行输出每个价格
相关问题 更多 >
编程相关推荐