【发布时间】:2020-07-23 00:37:54
【问题描述】:
@app.route('/upload', methods=["GET", "POST"])
def upload():
if request.method == 'POST':
file = request.files['upFile']
file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
dir = app.config['UPLOAD_FOLDER']+ file.filename
cmd = "INSERT INTO posts (title, author, file, date, subject, field ) VALUES (%s, %s, %s, %s, %s, %s)"
post = (request.form["title"], session['user_name'], dir, x, request.form["subject"], request.form.getlist("field[]"))
crsr.execute(cmd, post)
mydb.commit()
return redirect(url_for('upload'))
else:
return render_template('upload.htm')
它返回:MySQLInterfaceError: Python 类型列表无法转换
【问题讨论】:
-
欢迎来到 Stackoverflow!为了帮助其他人更好地解决您的问题,请在您的帖子中分享有关您的问题的更多信息,代码 sn-ps 是让其他支持者更清楚地了解可能是什么问题的最佳方式
-
这将返回一个列表:`request.form.getlist("field[]")
. Why are you retrieving a list here? What is the datatype of thefield` 列在数据库表中?
标签: python mysql python-3.x flask mysql-python