Flask-将数据从数据库保存到列表

时间:2021-07-09 10:07:45

标签: python postgresql

我编写了 Flask 应用程序,在这个应用程序中,我想从我的 postgresql 数据库中获取所有用户。 我想将我的所有用户保存到用户对象列表中,但我有一个错误“元组索引必须是整数,而不是 str”。

            <div id="app">
                <div class="col-3">
                    <div v-for="product in products" class="producte">
                        <div class="imgdesc">
                            <img :src="product.urlimg" class="img-fluid"><br>
                            {{ product.desc }}<br>
                        </div>
                        <img v-if="product.cartell === 'new'" src="imgs/sign_new_offer.png" class="cartell">
                        <img v-if="product.cartell === 'offer'" src="imgs/sign_offer.png" class="cartell">
                    </div>
                </div>
            </div>
        </div>

也许有人知道如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

User(['UserId'] 应该是 row(['UserId'] . 此外,您想返回列表列表。 每个列表代表一个用户。 所以你的代码应该为每个用户创建一个单独的列表或字典。 使用行 [0] 等来获取数据

相关问题