I am trying to write a Django application and I am stuck at how I can call a view function when a button is clicked.
In my template, I have a link button as below, w
here is a pure-javascript, minimalistic approach. I use JQuery but you can use any library (or even no libraries at all).
An example
Alternative approach
Instead of placing the JavaScript code, you can change your link in this way:
Check It Out
and in your views.py:
def YOUR_VIEW_DEF(request, pk):
YOUR_OBJECT.objects.filter(pk=pk).update(views=F('views')+1)
return HttpResponseRedirect(request.GET.get('next')))