# app.py (or your routes file) from flask import Flask, render_template from db import get_db_connection app = Flask(__name__) @app.route('/products') def products(): conn = get_db_connection() try: with conn.cursor() as cursor: # All products cursor.execute("SELECT * FROM products WHERE product_price >= 1 AND id >= 1271 ORDER BY id DESC LIMIT 21") all_products = cursor.fetchall() # Trending products (the query from your original PHP) cursor.execute("SELECT * FROM products WHERE bill_price >= 1 AND id >= 1271 ORDER BY category_id DESC, id DESC LIMIT 7") trending = cursor.fetchall() finally: conn.close() return render_template('products.html', all_products=all_products, trending=trending)