python - MySQLInterfaceError:无法转换 Python 类型列表
问题描述
@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 类型列表无法转换
解决方案
一种解决方案是像这样将列表转换为字符串。
','.join(list)
推荐阅读
- java - Java 有(显然)矛盾的作用域
- selenium - 从搜索下拉列表中选择值在硒中不起作用
- regex - Dreamweaver 正则表达式将 id 与 YUI 格式匹配
- sql-server - 多个重复的 IF 语句与存储过程中带有循环的单个 IF
- graph - 接口上的 SNMP/mrtg/流量报告不正确
- f# - 在 F# 生成器中获取空值
- javascript - 在 React useEffect 挂钩中引用过时的状态
- ruby-on-rails-4 - 为什么设计会生成这种格式的确认 URL?
- c# - 如何让用户控件适合窗口的网格?
- gcc - CMake:C 编译器无法编译简单的测试程序