<form action="/listing_image_upload" method="post" class="contact-form" enctype="multipart/form-data" style="padding: 30px; margin-left: 30px; margin-right:30px;"> <input type="hidden" class="form-control" name="listings_id" id="listings_id" value="{{one_listing.listings_id}}"> <input type="hidden" class="form-control" name="listing_id" id="listing_id" value="{{one_listing.id}}"> <div class="mb-3"> <label for="imgurl"> Image Upload: <input type="file" class="form-control" name="photo_name" id="photo_name"> </label> </div> <button type="submit" class="btn btn-primary">UPLOAD IMAGES</button> </form> <div style ="display: flex;"> {% for image in all_images %} {% if one_listing.listings_id == image.listings_id %} <img class="myImg" src="{{ url_for('static', filename = 'img/listing_images/') }}{{image.photo_name}}" style="width:10%;"> <a href="/admin/delete_image/{{image.photo_name}}" style="text-decoration:none; color: red;">DELETE IMAGE</a> {% endif %} {% endfor %} </div>
@app.route("/admin/update_listing/<int:id>") def admin_update_listing(id): data= { "id":id } return render_template("admin/listings/admin_update_listings.html", one_listing = Listing.get_one_listing(data), all_agents = Agent.get_all(), all_property_types = Property.get_all_property_types(), all_offer_types = Offer.get_all_offer_types(), all_states = State.get_all_states(), all_cities = City.get_all_cities(), all_images = Listing_Image.get_all_listing_images()) @app.route("/listing_update", methods = ["POST"]) def admin_listing_update(): Listing.update_one_listing(request.form) return redirect(f"/admin/update_listing/{request.form['id']}") @app.route("/listing_image_upload", methods = ["POST"]) def admin_listing_image_upload(): data ={ 'id' : id, 'photo_name': upload_image('listing'), 'listings_id': request.form['listings_id'] } Listing_Image.create_listing_images(data) return redirect(f"/admin/update_listing/{request.form['listing_id']}") @app.route("/admin/delete_image/<string:photo_name>") def admin_delete_one_image(photo_name): data ={ 'photo_name' : photo_name } Listing_Image.delete_one_listing_image(data) os.remove(os.path.join('static/img/listing_images/', photo_name)) return redirect('/admin/listings') #need this to redirect to "/admin/update_listing/<int:id>"
GET
delete_image
<a>
POST
<form>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)