Hello my Django friends,
I’ve now worked my way through the Django documentation and I have the feeling - this is going to be tough.
At the moment I am not sure how my Pythen code can communicate with an “interaction” on the website - clearly via “Get” and “Post”, I understood that, but what about a click of a button?
For example, if I have a checkbox (or a button, etc.):
<input id="checkbox" type="checkbox" name="myTextEditBox" value="checked">
Then I could create an EventListener via JavaScript:
<script>
document.addEventListener("DOMContentLoaded", () => {
const checkbox = document.querySelector("#checkbox")
checkbox.addEventListener("click", () => {
console.dir(Hello Python - the CheckBox was clicked here?)
})
})
</script>
But how can I react to the event in Python - in my view.py? Is there a simple explanation for this?
I have already tried to solve this with an onclick function - but here too I was at a loss as to how to “activate” my function in Python.
It would be helpful for me to have a small (simple) example of what the python code would look like - if that is possible
< onclick="checkbox()" input id="checkbox" type="checkbox" name="myTextEditBox" value="checked">
<script>
function checkbox{
document.addEventListener("DOMContentLoaded", () => {
const checkbox = document.querySelector("#checkbox")
checkbox.addEventListener("click", () => {
console.dir("And now?")
})
})
}
</script>
Thanks very much