@house_blueprint.route('/images/', methods=['POST']) def newhouse.images():
# 获得图片(images:<
FileStorage:
'wa.jpg' ('image/jpeg')>)
images = request.files.get('house_image')
house_id = request.form.get('house_id')
# 得到upload的路径
upload_dir = os.path.join(os.path.join(BASE_DIR,'static'), 'upload')
# 得到上传图片要保存的路径
# 'D:\\project\\houseproject\\static\\upload\\wa.jpg'
url = os.path.join(upload_dir,images.filename)
# 保存图片
images.save(url)
house_image = HouseImage()
house_image.house_id = house_id
image_url = os.path.join(os.path.join('/static', 'upload'), images.filename)
house_image.url = image_url try:
house_image.add_update()
except:
return jsonify(status_code.DATABAE_ERROR)
house = House.query.get(house_id)
if not house.index_image_url:
house.index_image_url = image_url try:
house.add_update()
except:
return jsonify(status_code.DATABAE_ERROR)
return jsonify(code=status_code.OK, image_url=image_url)