下拉列表选择多个使用HTMX
我正在使用django,并且我正在将一些值传递给Views.py。通过htmx,
所以我有一个下拉列表,其中有多个选择,
<select class="custom-select mb-4" name="Wells3" multiple >
<option selected>Select Well</option>
{% for well in FieldWells %}
<option value="{{well.WellID}}">{{well.WellID}}</option>
{% endfor %}
</select>
我选择了两个或三个选择,然后使用ctrl
,然后我通过按钮发送请求,
<button class="btn btn-primary" hx-get="{% url 'Plot_Logs' %}" hx-target="#LogPlots"
hx-include="[name='Wells3']"
>Plot Logs</button>
因此,从视图中。
有什么选择吗?
非常感谢
I am using Django and I am passing some values to views.py via HTMX
So Frist I have a dropdown list with multiple choices
<select class="custom-select mb-4" name="Wells3" multiple >
<option selected>Select Well</option>
{% for well in FieldWells %}
<option value="{{well.WellID}}">{{well.WellID}}</option>
{% endfor %}
</select>
I selected two or three choices with Ctrl
then I send the request via a button ,
<button class="btn btn-primary" hx-get="{% url 'Plot_Logs' %}" hx-target="#LogPlots"
hx-include="[name='Wells3']"
>Plot Logs</button>
so in the views.py I receive only the last value of the selection.
Are there any options to add?
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能需要一个请求。在您的视图中列表:
这是我的模板片段 - 与您的模板片段非常相似。请注意将传递其他参数传递的hx-vals(在我的情况下从全局$商店中取出):
在我看来,我有:
不寻常的事情是request.get.get似乎可以正常工作(&amp;返回一个值)这并不是真的有帮助。
希望这会有所帮助
You probably need a request.getlist in your view:
Here's my template fragment - very similar to yours. Note the hx-vals to pass in other parameters (in my case taken out of a global $store):
In my view I have:
The unusual thing is request.GET.get appears to work fine (& returns a one value) which is not really helpful.
Hope this helps
我能够获得所有值,只是在后端变化,
您以后可以迭代它
I was able to get all values just changing in the backend
you can later iterate it