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
添加回答
舉報