Flask - 从静态中删除图像(引导卡)
Flask - Delete image from static (boostrap card)
我正在尝试创建一个功能,让用户能够即时上传和删除一些图像。删除部分有效但不完全......它成功地从我的静态文件夹中删除了一个图像,但由于某种原因它只删除了它找到的第一张图像,而不是链接到引导卡的图像。
由于某种原因,它没有正确识别正确的值,我不知道为什么:
1。烧瓶
@app.route('/deleteImg', methods=['GET', 'POST'])
def deleteImg(row):
if request.method == 'POST':
image_to_del = request.values.get('image_to_del', None)
print(f'image_to_del:{image_to_del}')
os.remove(os.path.join(UPLOAD_FOLDER,image_to_del))
return redirect('/uploadimg')
return render_template('uploadimg.html')
2。 HTML
<form action="{{url_for('deleteImg')}}" method="POST">
<div class="row">
{% for row in pics %}
<div class="col-md-3 mt-3">
<div class="card">
<img src="{{ url_for('static', filename='pics/'+row)}}" alt="{{row}}" class="card_img_top" height="200">
<input type="hidden" name="image_to_del" class="image_to_del" value="{{row}}">Filename : {{row}}</input>
<h5 class="text-cent" >Filename : {{row}}</h5>
</div>
<div class="card-footer text-center">
<input type="submit" value="Delete" class="btn btn-success" />
</div>
</div>
{% endfor %}
</div>
</form>
我为那些可能感兴趣的人找到了这个解决方案。这是基于“Cairocoders”Flask delete image from db
的工作
1。烧瓶
@app.route('/deletelogo/<string:get_ig>', methods=['GET', 'POST'])
def deletelogo(get_ig):
print(f'get_ig :{get_ig}')
os.remove(os.path.join(LOGO_FOLDER,get_ig))
return redirect('/logoimg')
2。 HTML
<div class="row">
{% for row in pics %}
<div class="col-md-3 mt-3">
<div class="card">
<img src="{{ url_for('static', filename='logo/'+row)}}" alt="{{row}}" class="card_img_top" height="200">
<input type="hidden" name="image_to_del" class="image_to_del" value="{{row}}">Filename : {{row}}</input>
<h5 class="text-cent" >Filename : {{row}}</h5>
</div>
<div class="card-footer text-center">
<td><p><a href="/deletelogo/{{row}}" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span></a></p></td>
</div>
</div>
我正在尝试创建一个功能,让用户能够即时上传和删除一些图像。删除部分有效但不完全......它成功地从我的静态文件夹中删除了一个图像,但由于某种原因它只删除了它找到的第一张图像,而不是链接到引导卡的图像。 由于某种原因,它没有正确识别正确的值,我不知道为什么:
1。烧瓶
@app.route('/deleteImg', methods=['GET', 'POST'])
def deleteImg(row):
if request.method == 'POST':
image_to_del = request.values.get('image_to_del', None)
print(f'image_to_del:{image_to_del}')
os.remove(os.path.join(UPLOAD_FOLDER,image_to_del))
return redirect('/uploadimg')
return render_template('uploadimg.html')
2。 HTML
<form action="{{url_for('deleteImg')}}" method="POST">
<div class="row">
{% for row in pics %}
<div class="col-md-3 mt-3">
<div class="card">
<img src="{{ url_for('static', filename='pics/'+row)}}" alt="{{row}}" class="card_img_top" height="200">
<input type="hidden" name="image_to_del" class="image_to_del" value="{{row}}">Filename : {{row}}</input>
<h5 class="text-cent" >Filename : {{row}}</h5>
</div>
<div class="card-footer text-center">
<input type="submit" value="Delete" class="btn btn-success" />
</div>
</div>
{% endfor %}
</div>
</form>
我为那些可能感兴趣的人找到了这个解决方案。这是基于“Cairocoders”Flask delete image from db
的工作1。烧瓶
@app.route('/deletelogo/<string:get_ig>', methods=['GET', 'POST'])
def deletelogo(get_ig):
print(f'get_ig :{get_ig}')
os.remove(os.path.join(LOGO_FOLDER,get_ig))
return redirect('/logoimg')
2。 HTML
<div class="row">
{% for row in pics %}
<div class="col-md-3 mt-3">
<div class="card">
<img src="{{ url_for('static', filename='logo/'+row)}}" alt="{{row}}" class="card_img_top" height="200">
<input type="hidden" name="image_to_del" class="image_to_del" value="{{row}}">Filename : {{row}}</input>
<h5 class="text-cent" >Filename : {{row}}</h5>
</div>
<div class="card-footer text-center">
<td><p><a href="/deletelogo/{{row}}" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span></a></p></td>
</div>
</div>