1👍
You should do it through javascript.
Store your url value as a JS variable:
<script> my_url = "{% url 'api:by_book' 'name' %}"; </script>
Change the anchor to a button with a onClick event that calls a function.
In that function you can build the URL with my_url and recovering the name of the input you want with JS.
After that, make a redirection:
window.location = "http://www.yoururl.com";
Source:stackexchange.com