我正在构建桌面应用程序UI,并尝试将所有内容移动到Flask中,以便可以在html/css/boostrap
中显示所有内容。你知道吗
但是下面的代码不起作用。你知道吗
如何让found.productId
和其他循环显示在ali.html
上?你知道吗
应用程序类型
from aliexpress_api_client import AliExpress
@app.route('/ali')
def ali():
aliexpress = AliExpress('1234', 'bazaarmaya')
data = aliexpress.get_product_list(['productId', 'productTitle', 'salePrice', 'originalPrice', 'imageUrl'],
keywords="shoes", pageSize='40')
for product in data['products']:
productId = product['productId']
productTitle = product['productTitle']
salePrice = product['salePrice']
originalPrice = product['originalPrice']
imageUrl = product['imageUrl']
founds = print(productId, productTitle, salePrice, originalPrice, imageUrl)
if founds == founds:
return render_template('ali.html', founds=founds)
return render_template('ali.html')
阿里.html
{% extends 'layout.html' %}
{% block body %}
<table>
<tr>
{% for found in founds %}
<td>{{found.productId}}</td>
<td>{{found.productTitle}}</td>
<td>{{found.salePrice}}</td>
<td>{{found.originalPrice}}</td>
<td>{{found.imageUrl}}</td>
{% endfor %}
</tr>
</table>
{% endblock %}
第一个问题是
print()
将返回None
。所以:只是等价于
founds = None
。基本上没用。你知道吗所以,首先要做的是给
founds
一个结构。您的选项基本上是dict
和list
。在您的示例中使用列表是最简单的(但不一定是您的实际代码):应用程序类型
注意:这两种方法都有问题。
for
循环将覆盖每个循环上的数据,因此您可能需要一个字典,但需要为它提供唯一的键。或者预先定义一个列表并在循环中应用它。本例只给出循环中的最后一项,由您来相应地处理。你知道吗然后:
阿里.html
如果将字典传递给模板并希望通过键访问内容,则可以使用
.
表示法。但首先要解决的还有其他问题,所以这个答案有可能螺旋式上升到太深的程度。jinja2
语法(在模板中)与常规python非常相似。你知道吗相关问题 更多 >
编程相关推荐