-1

I'm new to working with Flask and SQL, I am trying to create a simple front-end interface to deal with my database, I am using peewee as my ORM. This is my code:

```
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"))
```

The search function works fine if I run it in my python file, and the templates also work fine if I test using other variables e.g (a list of strings), but when I try to call it in my index function I get:

 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 -

I'm very new to the hole doing HTTP requests with python, so I'm not totally sure what I could try

  • it simply means that there is no such table in the database, you can fix this by first creating this table – QwertYou Jul 15 '22 at 19:13
  • There is a table, it works if I call it directly in my main.py file, maybe it is creating a file in a different location – Samuel Lino Jul 16 '22 at 14:28
  • this is strange, the error says that there is no such table, maybe you mixed up the name or are you connecting to the wrong db? – QwertYou Jul 16 '22 at 18:24

1 Answers1

1

You are probably using a relative path for your database. Use an absolute path instead.

db = SqliteDatabase('/full/path/to/database.db')
coleifer
  • 24,887
  • 6
  • 60
  • 75