为什么我不能读取我的数据库从我的Flask应用程序与peewee



我刚开始使用Flask和SQL,我正在尝试创建一个简单的前端接口来处理我的数据库,我使用peewee作为我的ORM。这是我的代码:

```
def search(term):
items = Product.select().where(Product.name == term)
my_list = []
for item in items:
p_str = "Product: {}, Price: {}, Description: {}, Quantity in stock: {}".format(item.name,item.price, item.description, item.quant)
my_list.append(p_str)
return my_list

@app.route("/", methods=["GET", "POST"])
def index(name="Index"):
if request.method == "POST":
product = request.form["item"]
my_item = search(str(product))
return redirect(url_for("store", item=my_item))
return render_template("index.html", title=name)
@app.route("/store")
def store(name="Store"):
return render_template("store.html", title=name, items=request.args.getlist("item"))
```

搜索函数工作良好,如果我在我的python文件中运行它,模板也工作良好,如果我使用其他变量进行测试,例如(字符串列表),但当我试图在我的索引函数中调用它时,我得到:

cursor.execute(sql, params or ())
peewee.OperationalError: no such table: product
127.0.0.1 - - [15/Jul/2022 10:12:25] "POST / HTTP/1.1" 500 -

我是一个非常新的洞做HTTP请求与python,所以我不完全确定我可以尝试

您可能正在使用数据库的相对路径。请使用绝对路径。

db = SqliteDatabase('/full/path/to/database.db')

最新更新