网页代码
<div>
<form action = "{{ url_for('addrec') }}" method = "POST">
<h3>进货登记</h3>
商品名<br>
<input type = "text" name = "gname" /></br>
生产厂家<br>
<input type = "text" name = "fname" ><br>
型号<br>
<input type = "text" name = "type" /><br>
单价<br>
<input type = "text" name = "price" /><br>
数量<br>
<input type = "text" name = "num" /><br>
总金额<br>
<input type = "text" name = "sum" /><br>
进货日期<br>
<input type = "text" name = "inyear" />年
<input type = "text" name = "inmonth" />月
<input type = "text" name = "inday" />日<br>
业务员编号<br>
<input type = "text" name = "eno" /><br>
<br>
<input type = "submit" value = "添加入库" /><br>
</form>
</div>
app.py
from flask import Flask, render_template, url_for,request
import sqlite3 as sql
import sqlite3
DEBUG = True
app = Flask(__name__)
#连接html文件
@app.route('/')
def home():
return render_template('sell_head.html')
@app.route('/ingood')
def new_good():
return render_template('sell_in.html')
@app.route('/addrec',methods = ['POST', 'GET'])
def addrec():
if request.method == 'POST':
try:
gname = request.form['gname']
factory = request.form['fname']
type = request.form['type']
price = request.form['price']
num = request.form['num']
sum = request.form['sum']
inyear = request.form['inyear']
inmonth = request.form['inmonth']
inday = request.form['inday']
eno = request.form['eno']
with sql.connect("sell_system.db") as con:
cur = con.cursor()
cur.execute("INSERT INTO good (gname,factory,type,price,num,sum,inyear,inmonth,inday,eno)VALUES (?,?,?,?,?,?,?,?,?,?)",(gname,fname,type,price,num,sum,inyear,inmonth,inday,eno) )
con.commit()
msg = "Record successfully added"
except:
con.rollback()
msg = "error in insert operation"
finally:
return render_template("result.html",msg = msg)
con.close()
输入进货登记的数据后点击添加入库,跳转页面 error in insert operation
到底是哪里出问题了