大家好。我在使用烧瓶上传图像时遇到了一个小问题。我可以在localhost中的flask上上传图像(Web应用程序托管在我的桌面上)。但是当我在Online Server上加载烧瓶应用程序时,我总是遇到“FileNotFoundError”。我还将权限更改为777,但仍然无法正常工作。
这是 html 上传代码。
<form name="edit_vehicle_info" action="/vehicle_info_form/" method="POST" enctype="multipart/form-data" class="formfield">
<div class="form-group">
<label for="changeVehicleImg">Vehicle Image</label>
<input type="file" id="changeVehicleImg" name="changeVehicleImg" accept="image/*">
</div>
这是python上传代码。
#vehicle_info_form
@app.route('/vehicle_info_form/', methods=['GET', 'POST'])
def vehicle_info_form():
try:
if request.method == "GET":
return render_template(
'vehicleInfo.html'
)
elif request.method == "POST":
inputVehicleImg = request.files['changeVehicleImg']
if inputVehicleImg.filename == "":
inputVehicleImg_filename = ""
else:
print(inputVehicleImg.filename)
print(app.config['UPLOAD_FOLDER_IMG_VEHICLE'])
inputVehicleImg_filename = secure_filename(inputVehicleImg.filename)
inputVehicleImg.save(os.path.join(app.config['UPLOAD_FOLDER_IMG_VEHICLE'], inputVehicleImg_filename))
print ('success')
except Exception as e:
print(e)
return redirect(url_for('vehicle_info_form'))
python上传代码可以打印,然后之后,发生错误。inputVehicleImg.filenameapp.config['UPLOAD_FOLDER_IMG_VEHICLE']
慕标琳琳
相关分类