How to perform the function of Django by clicking on a button in html template?

There is a function implemented in the Django view, it returns a value. How to call a function from the frontend? I can assume that this is done using django forms and post requests, but I could be wrong. A little idea how to do this if there are multiple functions, and is implemented in a single view all
if request == 'POST':
 code


For example, in php this is implemented by simply tapping the button ID:
<?php

function testfun()
{
echo "Your test function on button click is working";
}

if(array_key_exists('test',$_POST)){
testfun();
}

?>


Skimmed through the documentation, nothing particularly similar not found (maybe bad looking). Point to the right path, please.
April 4th 20 at 13:08
1 answer
April 4th 20 at 13:10
Solution
as an option
@register.simple_tag
def your_custom_tag_django (url):
 return "window.location='" + url +"';

<form action="/add/book" method="post">{% csrf_token %}
 {{ form }}
 <button onclick="{% your_custom_tag_django '/books' %}">Cancel</button>
 <button type="submit">OK</button>
</form>

Find more questions by tags Django