title: ajax like count is showing the same for every post in django
body: <p>The problem is due to the ajax implementation in my django twitter clone app, the like count for every post is showing the same after clicking the like button.but after the page refresh that is okay. I am near to solve the problem but stuck somehow.</p>
  
  <p>view:</p>
  
  <pre><code>def add_like(request):
      if request.method == 'GET':
          ans_id = request.GET['id']
          user = request.user.profile
          liked_tweet = get_object_or_404(Tweet, pk=ans_id)
  
  if ans_id:
      # creating instance by sending the Like table fields
      instance, created = Like.objects.get_or_create(liker=user, liked_tweet=liked_tweet)
      ans = Tweet.objects.get(id=(int(ans_id)))
      if ans:
          likes = ans.likes + 1
          ans.likes = likes
          ans.save()
  # returns the likes field of a tweet post
  return HttpResponse(likes)
  </code></pre>
  
  <p>the HttpResponse is sending the likes and that creates the problem I guess.</p>
  
  <p>the template:</p>
  
  <pre><code>    {% for tw in tweets %}
      &lt;div class="blog-post"&gt;
          &lt;p&gt;
              {{ tw.content|safe }}&lt;br&gt;&lt;hr&gt;
              &lt;small class="small"&gt;
                  লিখসে -
                  &lt;!-- in the "href" we can pass data like "pk", accessing by the structure the current object is based on--&gt;
                  &lt;a href="{% url 'profile' pk=tw.tweeter.user.pk %}"&gt;{{ tw.tweeter.user.username|capfirst }}&lt;/a&gt;
              &lt;/small&gt;
          &lt;/p&gt;
          {% if user.is_authenticated %}
          &lt;button class="btn btn-default likes-button" type="button"
          data-ansid="{{ tw.pk }}"&gt;Like&lt;/button&gt;
          &lt;i&gt; Total Likes: &lt;/i&gt;&lt;em class="like_count"&gt;{{ tw.likes }}&lt;/em&gt;
          {% endif %}
      &lt;/div&gt;
  </code></pre>
  
  <p>the ajax script:</p>
  
  <pre><code>$(".likes-button").click(function(e) {
  if ($(this).html() == "Like") {
      $(this).html('Unlike');
      //alert("js working");
      // error was there for "data" insted of "attr"
      var ansid = $(this).attr("data-ansid");
      $.ajax({
          url: '{% url "add_like" %}',
          type: 'get',
          data: {id: ansid}
      }).done(function (data) {
          alert("success");
          $('.like_count').html(data);
          //$('#likes').hide();
      }).fail(function (err) {
          alert(err);
      });
  }
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <p><a href="https://i.stack.imgur.com/weywB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/weywB.png" alt="before hitting like"></a>
  <a href="https://i.stack.imgur.com/psHdR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/psHdR.png" alt="after hitting like"></a></p>