1 回答
TA贡献1830条经验 获得超9个赞
我通过更新.我用于获取完整的当前路径并添加应保存图像的路径。app.config['UPLOAD_FOLDER_IMG_VEHICLE']os.getcwd()
首先,我通过添加和来检查错误的根源是什么。tryexcept FileNotFoundError:
#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)
try:
inputVehicleImg.save(os.path.join(app.config['UPLOAD_FOLDER_IMG_VEHICLE'], inputVehicleImg_filename))
except FileNotFoundError:
print("File does not exist")
print ('success')
except Exception as e:
print(e)
return redirect(url_for('vehicle_info_form'))
我尝试上传图像并在控制台中返回。File does not exist
然后,我检查图像应上传的路径。app.config['UPLOAD_FOLDER_IMG_VEHICLE']
print(app.config['UPLOAD_FOLDER_IMG_VEHICLE'])
在那里,我发现我的在线服务器中的路径不一样,所以我更新了它。
import os
path = os.getcwd()
print(path)
UPLOAD_FOLDER_IMG_VEHICLE = path + "/apps/FMS/static/images/vehicleInfo"
app.config['UPLOAD_FOLDER_IMG_VEHICLE'] = UPLOAD_FOLDER_IMG_VEHICLE
添加回答
举报