为了建立一个模式来确认一个删除动作,我尝试动态设置一个删除url,使用超文本。以下是(部分)代码:
<!-- open the modal and set the (Django) delete url -->
<button
_="on click set @hx-delete of #confirm_delete_button to '{% url view_name record.pk %}'">
<!-- the delete confirmation button -->
<button
id="confirm_delete_button"
hx-delete="to_be_set_later_by_hyperscript"
hx-trigger="click"
hx-target="body" {# TODO: change #}
hx-swap="delete">
Delete
</button>起初,一切似乎都如预期的那样工作,因为我可以在检查器中看到正确的删除url:

但是,单击该按钮时,我得到了一个Not Found: /to_be_set_later_by_hyperscript错误,表明即使设置了属性,HTMX也使用“旧”url。
我该怎么办?谢谢。
发布于 2022-07-29 05:31:07
不知道为什么它不适用于“集合”,但以下几点对我来说是有效的:
<button
_="on click add [@hx-delete={% url view_name record.pk %}] to #confirm_delete_button">
Open
</button>
<!-- the delete confirmation button -->
<button
id="confirm_delete_button"
hx-delete=""
hx-trigger="click"
hx-target="body"
hx-swap="delete">
Delete
</button>https://stackoverflow.com/questions/73151686
复制相似问题