本文介紹了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)
這篇關于MySQLInterfaceError:無法轉換Python類型列表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,