

I think you should write a classmethod in your model. Return render_template_string(template_add) #return render_template("add.html", item=item) (item_type, item_receipt, item_amount, item_description)) Return render_template_string(template_edit, delete(number):Ĭur.execute("DELETE FROM SubmitClaim WHERE id = ?", (number,)) #return render_template("edit.html", item=item) (item_type, item_receipt, item_amount, item_description, item_id))Ĭur.execute("SELECT * FROM SubmitClaim WHERE id = ?", (number,)) Item_description = request.formĬur.execute("UPDATE SubmitClaim SET type = ?, receipt = ?, amount = ?, description = ? WHERE id = ?",


Return render_template_string(template_list, methods=) #return render_template("list.html", rows=rows) from flask import Flask, request, render_template_string, redirectĬur.execute("""INSERT INTO SubmitClaim (type, receipt, amount, description) VALUES (?, ?, ?, ?)""", After first run you need to skip generate_data() because it will add another 10 rows in next execution. I used render_template_string instead of render_template to keep all in one file - so everyone can fast copy code to one file and test it.Ĭode at start create TABLE in database and insert 10 fake rows. Doing this on one page would need to use separated form in every row.
#Python flask sqlite tutorial update#
You tried to display all rows and also UPDATE single row. In your version you had mixed LIST with EDIT. I added also page which can ADD and DELETE row. Page LIST show table with all rows in database.Īnd every row has button EDIT which open other page to edit only one row. Return render_template("editclaim.html", rows=rows) However, I am able to INSERT AND RETRIEVE from DB Browser SQlite.Ĭurrently, I am only able to retrieve the data but I cannot update the fields.ĭescription = request.formĬur.execute("UPDATE items SET type = ?, uploadre = ?, amt = ?, description = ?\ UnboundLocalError: local variable 'type' referenced before assignment
