我正在使用
基本渲染模板位于
104 {% if 'DELETE' in allowed_methods %}
105 <form class="button-form" action="{{ request.url }}" method="DELETE" class="pull-right">
106 <!-- csrf_token -->
107 <input type="hidden" name="_method" value="DELETE" />
108 <button class="btn btn-danger js-tooltip" title="Make a DELETE request on the resource">DELETE</button>
109 </form>
110 {% endif %}
但不是,瀏覽器現在發送GET帶有查詢字串_method=DELETE的DELETE請求,而不是請求/方法。

使用向 API 發送請求時一切正常 curl
你們中具有良好Flask html 渲染技能的人可以檢查一下并對其進行測驗嗎?
uj5u.com熱心網友回復:
從未見過形式method=DELETE。MDN 檔案說它應該是 aGET或POST. 另請參閱這個舊的stackoverflow 問題,該問題也說它在表單中不受支持。
您參考的模板用于 API,因此在我看來,它們支持對 API 的直接呼叫(例如支持 PUT、DELETE 等curl或Postman支持 PUT、DELETE 等)和通過表單呼叫(只能是 GET 或 POST )
您應該將原始代碼保留在何處method = POST并添加POST為def notes_detail您應該擁有的方法
@app.route("/<int:key>/", methods=['GET', 'POST', 'PUT', 'DELETE'])
def notes_detail(key):
uj5u.com熱心網友回復:
我放棄了讓瀏覽器發送DELETE請求的努力,并處理表單隱藏輸入,保留POST為表單的方法
104 {% if 'DELETE' in allowed_methods %}
105 <form class="button-form" action="{{ request.url }}" method="POST" class="pull-right">
106 <!-- csrf_token -->
107 <input type="hidden" name="_method" value="DELETE" />
108 <button class="btn btn-danger js-tooltip" title="Make a DELETE request on the resource">DELETE</button>
109 </form>
110 {% endif %}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/347971.html
