After conducting thorough research, I was unable to find a solution for handling META requests in Django with Ajax. The constant page refreshing severely impacts the user experience. Here is an example of the code:
template
<a href="/like/?id={{ car.id }}" ># of likes: {{ car.likes }}</a>
views.py
def like_page(request):
if 'id' in request.GET:
id = request.GET['id']
car = Cars.objects.get(id=id)
car.likes += 1
car.save()
if 'HTTP_REFERER' in request.META:
return HttpResponseRedirect(request.META['HTTP_REFERER'])
return HttpResponseRedirect('/')
In this setup, the template sends the object ID, and the view increments the like count by 1 each time it is triggered. However, the lack of Ajax results in frequent page reloads.
Being more experienced in backend development, I am unfamiliar with implementing jQuery and Ajax. If anyone could provide guidance on how to solve this issue, it would be greatly appreciated. Thank you :)