这是查询语句 这个正常
@app.route('/select',methods=['POST'])
def selects():
name =request.form.get("name")
con = sqlite3.connect("liuyan.db") # 建立数据库连接
con.row_factory = sqlite3.Row # 设置row_factory,对查询到的数据,通过字段名获取列数据
cur = con.cursor() # 获取游标
cur.execute("select * from card where name=? ",(name,)) # 执行sql语句选择数据表
rows = cur.fetchall() # 获取多条记录数据
con.close()
return render_template('cha.html', rows=rows)
@app.route('/add',methods=['POST'])
def adds():
name=request.form.get("name")#获取前端送过来的name数据
text=request.form.get("text")#获取内容
tim=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())#时间格式
con =sqlite3.connect("liuyan.db")#连接数据库
cur =con.cursor()
cur.execute("insert into card (name,text,time) values (?,?,?)",(name,text,tim))#向数据库插入一条记录
con.commit()
con.close()
return render_template('add.html' )
上面这个插入字段的方法 在电脑上运行不报错 放到服务器上 就报错
[2022-09-25 19:42:47,336] ERROR in app: Exception on /add [POST]
Traceback (most recent call last):
File "/www/wwwroot/ly/0cc86c81b505708557e3c341463968c2_venv/lib/python3.9/site-packages/flask/app.py", line 2525, in wsgi_app
response = self.full_dispatch_request()
File "/www/wwwroot/ly/0cc86c81b505708557e3c341463968c2_venv/lib/python3.9/site-packages/flask/app.py", line 1822, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/www/wwwroot/ly/0cc86c81b505708557e3c341463968c2_venv/lib/python3.9/site-packages/flask/app.py", line 1820, in full_dispatch_request
rv = self.dispatch_request()
File "/www/wwwroot/ly/0cc86c81b505708557e3c341463968c2_venv/lib/python3.9/site-packages/flask/app.py", line 1796, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
File "/www/wwwroot/ly/main.py", line 28, in adds
cur.execute("insert into card (name,text,time) values (?,?,?)",(name,text,tim))#向数据库插入一条记录
sqlite3.OperationalError: unable to open database file