Is there anyway i can play an audio and then make theHttpResponseRedirect in django?

Like i made this blog in Django where you can like and unlike posts etc..., but when you press unlike I would like to play a sound and then make the request to remove the like. Is it possible to do that? I tried to wrap my head in an if statement, but I'm kinda new to Django so I'm lost

MY Postdetail view

class PostDetailView(DetailView):
    model = Post
    template_name = "post_detail.html"
    context_object_name = 'detail'

    def get_context_data(self, *args, **kwargs):

        context = super(PostDetailView, self).get_context_data()
        total = get_object_or_404(Post, id=self.kwargs['pk'])
        total_likes = total.total_likes()

        liked = False
        if total.likes.filter(id=self.request.user.id).exists():
            liked = True

        context['total_likes'] = total_likes
        context['liked'] = liked
        return context

My like function

def LikeView(request, pk):
    post = get_object_or_404(Post, id=request.POST.get('post_id'))
    liked = False
    if post.likes.filter(id=request.user.id).exists():
        post.likes.remove(request.user)
        liked = False
    else:
        post.likes.add(request.user)
        liked = True
    return HttpResponseRedirect(reverse('detail-post', args=[str(pk)]))

Where the function with the audio is called

 <button type="submit" onclick="play()" name="post_id" value="{{ object.id }} "
                            class="btn mb-3 mx-2 btn-outline-danger">unlike
                        </button> | {{ total_likes }}

The audio function

<script>
    function play() {
      var audio = document.getElementById("audio");
      audio.play();
    }
  </script>

  <audio id="audio" src="https://res.cloudinary.com/volendam/video/upload/v1664620564/memesong_dzacbp.mp3"></audio>
Back to Top