<input type="number" x-model="inputValue" min="1" max="{{ page.paginator.num_pages }}"
placeholder="Enter a number">
<button type="button" hx-get="?page={{ ????? }}">Go</button>
这里是从 htmx 示例扩展它的代码,用于创建一个用于部分加载分页的转到页面 https://github.com/adamchainz/django-htmx/tree/main/example
问题是我无法配置 hx-get 来获取 inputValue 字段的值。
您尝试使用 Django 模板插值填充参数,但那是服务器端,并且该值仅在客户端已知。
相反,您需要告诉 HTMX 从客户端获取哪些值,并将其包含在
GET
请求中。您可以使用 hx-include 属性来执行此操作。您还需要向 name
元素添加 input
属性:
<input name="page" type="number" x-model="inputValue" min="1" max="{{ page.paginator.num_pages }}" placeholder="Enter a number">
<button type="button" hx-get="" hx-include="[name='page']">Go</button>