在我的烧瓶应用程序中,我希望用户能够将图像上传到静态文件夹内的文件夹(称为壁纸)。目前我收到了一个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>
慕斯王
相关分类