How can I call my view function from a button click and have it return something that would result in my web page not reloading? It seems that I must return an HTTP request in some way in views.py or I get an error. "I do not wish to stop the form submission". I would prefer not to use Ajax at this moment. I have a page with a long list of objects from my database that users can input quantities and click a button which sends the form data to a cart object. In doing this, the corresponding view function is triggered and returns some sort of HTTP Response which results in the page loading in some way. I would like it so that absolutely nothing happens when a button is clicked, other than the form data being submitted. Not even a redirect to the same page. This is because I don't want the user to lose there place on the page and have to scroll through a list of objects to find where they were.
views
def add_to_cart(request, product_id):
return HttpResponse('')
url path
path('cart/add/<product_id>', home_views.add_to_cart, name='add_to_cart'),
Quote
<form action="{% url 'add_to_cart' product.id %}" method="post">{% csrf_token %}</form>