如何在Flask中跨多个页面显示字典?

时间:2019-07-13 20:00:10

标签: python dictionary flask pagination

我的数据库中有1000多个项目,我想在我的网站上显示这些产品。这些项目作为字典获取。我在StackOverflow上搜索了此问题。我发现了一些东西,但这些物品是作为清单拿来的。

@app.route("/",methods = ["GET","POST"])
def index():
    if request.method == "GET":
        cursor = mysql.connection.cursor()
        sorgu = "SELECT * from all_products"
        result = cursor.execute(sorgu)
        if result > 0:
            products = cursor.fetchall()
            totalproducts = len(products)
            totalproductsinpage = countproductsall(products)
            success = int((totalproducts - totalproductsinpage )* 100 / totalproducts)
            return render_template("index.html",products = products,totalproducts = totalproducts,totalproductsinpage = totalproductsinpage,success = success)
        else:
            flash("Ürün bulunamadı!","warning")
            return render_template("index.html")

0 个答案:

没有答案