当用户点击一个复选框时,值将被发送到一个javascript函数,该函数将获取值并异步地检查数据库中是否有任何事件,但我不知道在Django中是否有可能,我见过序列化器,但我认为它不会起作用,因为它不仅从数据库中捕捉数据,而且进行查询。有办法做到这一点吗?
requisite = requisite.objects.filter(requisite__discipline__id=33)
上面的代码将检索所需的数据,但我需要从下面的代码中获取此编号
<input class="form-check-input" type="checkbox" value="{{ discipline.id }}" id="flexCheckDefault{{ discipline.name }}" onclick="checkRequisite(this.defaultValue)">
1条答案
按热度按时间2lpgd9681#
First create a view that will receive the information from your JavaScript:
Next, add a path to that view:
Then, in your js file, or your you send the AJAX request:
Your
checkRequisite
function could call the async function above, and process the answer however you wish. Of course, the answer I'm sending in the view is just a string, but it could be more data.The answer is incomplete, but if I had more of your code, perhaps I could come up with something more complete and specific, but I think the general idea works.