简体   繁体   English

HTMX hx-delete 与 hx-include 一起使用

[英]HTMX hx-delete with hx-include together

I am using the hx-delete to delete a record from db table.我正在使用hx-delete从 db 表中删除一条记录。 but along with it, I need to send other parameters with the request using hx-include .但除此之外,我还需要使用hx-include随请求发送其他参数。

   hx-trigger="click" 
   hx-delete="{{ url_for('htmx_delete', task_id=task.id) }}" 
   hx-include="[name='ordertype'],[name='orderby'],[name='filterby'],[name='searchField']" 
   hx-target="#tasks-list" 
   hx-swap="innerHTML" 
   hx-confirm="Are you sure you wish to delete this task?"

On the server side (Flask), I am using the DELETE method as well:在服务器端(Flask),我也在使用DELETE方法:

@app.route('/htmx_delete/<task_id>', methods=['GET', 'DELETE'])
def htmx_delete(task_id):

I can see the additional parameters in the payload.我可以看到有效载荷中的附加参数。 However, As expected I can't retrieve the additional parameters using fLASK request.args.get or request.form.get .但是,正如预期的那样,我无法使用 fLASK request.args.getrequest.form.get检索其他参数。

How can I access the additional parameters using the DELETE HTTP verb?如何使用 DELETE HTTP 动词访问其他参数? I can make this work using the GET verb on the client and server side, but I want to stick with DELETE.我可以在客户端和服务器端使用 GET 动词来完成这项工作,但我想坚持使用 DELETE。

thanks!谢谢!

Here's how you can retrieve the payload:以下是检索有效负载的方法:

from urllib.parse import parse_qs
payload_dict = parse_qs(request.body.decode('utf-8'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM