用烧瓶查询更新sqlite3

时间:2018-02-13 10:39:12

标签: python sqlite

有人可以建议我如何将输入文字从 edit.html 传递到 views.py app.route吗?我被困在那里,我正在努力学习更多烧瓶。

模板/ edit.html

 <form action="{{ url_for('update_entry', update_id=row['id']) }}"method="post">
 <input type = "text"  name="update_id" value="{{row["id"]}}" />
 <input type = "text" name="nm" value="{{row["name"]}}"  />
 <input type = "text" name="city" value="{{row["city"]}}" />
 <input type = "text" name="pin" value="{{row["pin"]}}"   /> 
 <input type="Submit" value="Update">

views.py

@app.route('/update/<int:update_id>',  methods=['POST'])
def update_entry(update_id):
   nm = request.form['nm']
   addr = request.form['add']
   city = request.form['city']
   pin = request.form['pin']
   con = sql.connect("database.db")
   con.row_factory = sql.Row
   cur = con.cursor()
   update_id=int(update_id)
   cur.execute("update students set name=?, addr=?, city=?, pin=? where id=?", (nm, addr, city, pin, update_id,))
   con.commit()
   rows = cur.fetchall();
   return redirect("http://192.168.1.1:4000/list")

感谢您的帮助。

0 个答案:

没有答案
相关问题