I cannot read the value of a select element via a htmx PUT hx-put
, method to the flask view function. The select is in a modal body. I am almost certain I need to read the PUT value from the request.get_json()
function. The put executes and I can print the request
object in the view function, but no data.
<div class="modal-dialog modal-dialog-centered"><div class="modal-content"><div class="modal-header"><h5 id="muctor" class="modal-title">{{ title }}</h5><h5 class="modal-title">{{ title }}</h5></div><div class="modal-body"><div class="dropdown"><select id="selected_storage" name="pavvy" class="form-select form-select-sm" aria-label=".form-select-sm example"> {% for i in items %}<option value="{{ i.id }}">{{ i.name }}</option> {% endfor %}</select></div></div><div><input type="text" id="username" placeholder="Enter your name"></div><div class="modal-footer"><button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button><button type="button" hx-put="{{ url_for('lots_bp.update_storage', id=id) }}" hx-include="#selected_storage" hx-swap="none" hx-headers="{'Content-Type': 'application/json'}" hx-trigger="click" class="btn btn-sm btn-primary">Submit</button></div></div></div>
@lots_bp.route("/update_storage/<int:id>", methods=["PUT"])def update_storage(id: int): print(request.get_json()) return ""
This is giving me the following error in the console.
SyntaxError: Expected property name or '}' in JSON at position 1 (line 1 column 2) at JSON.parse (<anonymous>) at S (htmx.min.js:1:4795) at dr (htmx.min.js:1:34354) at sr (htmx.min.js:1:31612) at ce (htmx.min.js:1:37724) at htmx.min.js:1:21402 at HTMLButtonElement.i (htmx.min.js:1:17838)y @ htmx.min.js:1S @ htmx.min.js:1dr @ htmx.min.js:1sr @ htmx.min.js:1ce @ htmx.min.js:1(anonymous) @ htmx.min.js:1i @ htmx.min.js:1htmx.min.js:1 PUT http://localhost:5000/lot/update_storage/1 415 (UNSUPPORTED MEDIA TYPE)ce @ htmx.min.js:1(anonymous) @ htmx.min.js:1i @ htmx.min.js:1htmx.min.js:1 Response Status Error Code 415 from /lot/update_storage/1