title: TypeError statusText: "Internal Server Error" for a simple post "LIKE" feature in Django using Ajax
body: <p>I have a simple post like toggle button where a user can <code>like</code> a post. It is working fine without adding jQuery and Ajax methods. However I need to add Ajax to remove page refresh. Below is my code adding Ajax and jQuery. What am I doing wrong?</p>
  
  <p>I have added the error to the bottom, It says</p>
  
  <blockquote>
    <p>got an unexpected keyword argument 'username'</p>
  </blockquote>
  
  <p>How do I fix that?</p>
  
  <p>my models are</p>
  
  <pre><code>class Post(models.Model):
      user = models.ForeignKey(User, related_name='posts')        
      title = models.CharField(max_length=250, unique=True)
      slug = models.SlugField()
      message = models.TextField()       
      likes = models.ManyToManyField(User, blank=True, related_name='post_likes')
  
      def get_api_like_url(self):
         return reverse('posts:like_api', kwargs={'username': self.user.username,
                                           'slug': self.slug})
  
      def get_absolute_url(self):
         return reverse('posts:single', kwargs={'username': self.user.username,
                                             'slug': self.slug})
  
      def get_like_url(self):
         return reverse('posts:like', kwargs={'username': self.user.username,
                                           'slug': self.slug})
  </code></pre>
  
  <p>My views are</p>
  
  <pre><code>class PostLikeAPIToggle(APIView):
      authentication_classes = (authentication.SessionAuthentication,)
      permission_classes = (permissions.IsAuthenticated,)
  
      def get(self, request, slug=None, format=None):
          obj = get_object_or_404(Post, slug=slug)
          url_ = obj.get_absolute_url()
          user = self.request.user
          if user.is_authenticated():
              if user in obj.likes.all():
                  obj.likes.remove(user)
                  liked = False
              else:
                  obj.likes.add(user)
                  liked = True
              data = {
                  "post": obj,
                  "liked": liked,
                  "total_likes": obj.likes.all()
              }
              return Response(data)
  </code></pre>
  
  <p>In my template I have the below code</p>
  
  <pre><code>&lt;script&gt;
      $(document).ready(function () {
          $(".like-btn").click(function (e) {
              e.preventDefault();
              var this_ = $(this);
              var likeUrl = this_.attr("data-href");
              $.ajax({
                  url : likeUrl,
                  method: "GET",
                  data: {},
                  success: function (data) {
                      console.log(data);
                      // $("#like-section").html(response)
                  }, error: function (error) {
                      console.log("error");
                      console.log(error);
                  }
              })
          })
      })
  &lt;/script&gt;
  
  &lt;div class="text-center"&gt;
  {% if user in post.likes.all %}
      &lt;a class="like-btn" data-href="{{post.get_api_like_url}}" href="{{post.get_like_url}}"&gt;
          &lt;img src="{% static 'images/HEART.RED.png' %}" height="25px"&gt;
      &lt;/a&gt;&lt;br/&gt;
  {% else %}
      &lt;!--&lt;a href=""&gt;&lt;img src="{% static 'images/HEART.png' %}" height="25px"&gt;&lt;/a&gt;&lt;br/&gt;--&gt;
      &lt;a class="like-btn" data-href="{{post.get_api_like_url}}" href="{{post.get_like_url}}"&gt;
          &lt;img src="{% static 'images/HEART.png' %}" height="25px"&gt;
      &lt;/a&gt;&lt;br/&gt;
  {% endif %}
  </code></pre>
  
  <p>Below is my URL for calling the like button</p>
  
  <pre><code>url(r'^(?P&lt;username&gt;[-\w]+)/(?P&lt;slug&gt;[-\w]+)/like_api/$', views.PostLikeAPIToggle.as_view(), name='like_api'),
  </code></pre>
  
  <p>Below is the error that I am getting</p>
  
  <blockquote>
    <p>responseText: "TypeError at /posts/charlize/singes-boat-new-york/like_api\nget() <strong>got an unexpected keyword argument 'username'\n\nRequest</strong> Method: GET\nRequest URL:</p>
  </blockquote>