在我的烧瓶应用程序中,我希望用户能够将图像上传到静态文件夹内的文件夹(称为壁纸)。目前我收到了一个flask.debughelpers.DebugFilesKeyError,但是我在使用的键中没有看到任何错误我尝试过的flaskapp.py@app.route('/changeWallpaper' , methods = ['POST', 'GET'])def change_home_wallpaper(): UPLOADS_PATH = join(dirname(realpath(__file__)), 'static\\wallpaper') if request.method == "POST": wallpaper = request.files['wallpaper'] if wallpaper.filename != '': image = request.files['wallpaper'] image.save(os.path.join(UPLOADS_PATH, secure_filename(image.filename))) cur = db2.cursor() sql = f"UPDATE wallpaper set pic = {wallpaper.filename} where sno = 1" cur.execute(sql) db2.commit() cur.close() return redirect(url_for('home')) else: return redirect(url_for('home'))登录.html<div class="jumbotron"> <form action="{{url_for('change_home_wallpaper')}}" method="post"> <div class="container"> <input type="file" name="wallpaper"/> <input type="submit" class="btn btn-primary"/> </div> </form></div>
1 回答
慕斯王
TA贡献1864条经验 获得超2个赞
更新您的HTML
<form action="/path" method="post" enctype="multipart/form-data">
</form>
并加上{wallpaper.filename}引号。
添加回答
举报
0/150
提交
取消