title: Trying to Implement simple API in Django
body: <p>I am very new to Django and trying to implement small API for social media website where I can monitor if post has been liked and number of likes and later fetch API using JavaScript so I can like without refreshing the page using put method. Problem is that I largely failed because of lack of proper knowledge. I could not get the API working in the first place.</p>
  <p>models.py</p>
  <pre><code>from django.contrib.auth.models import AbstractUser
  from django.db import models
  
  class User(AbstractUser):
      pass
  
  class New_Post(models.Model):
      user = models.ForeignKey(User, null=True, on_delete=models.CASCADE)
      New_Post =  models.CharField(null=True, max_length=300)
      def __str__(self):
          return f&quot;{self.New_Post}&quot;
  
  class Likes(models.Model):
      user = models.ForeignKey(User, null=True, on_delete=models.CASCADE)
      like = models.BooleanField(default=False)
      New_Post =  models.ForeignKey(New_Post, null=True, on_delete=models.CASCADE)
      def serialize(self):
          return {
          &quot;id&quot;: self.id,
          &quot;post&quot;: self.New_Post,
          &quot;user&quot;: self.user,
          &quot;like&quot;: self.like
      }
  </code></pre>
  <p>views.py fragment</p>
  <pre><code>def likes(request):
      like = Likes.objects.all()
      return JsonResponse(like.serialize())
  </code></pre>
  <p>urls.py</p>
  <pre><code>urlpatterns = [
      path(&quot;&quot;, views.index, name=&quot;index&quot;),
      path(&quot;login&quot;, views.login_view, name=&quot;login&quot;),
      path(&quot;logout&quot;, views.logout_view, name=&quot;logout&quot;),
      path(&quot;register&quot;, views.register, name=&quot;register&quot;),
      path(&quot;Post&quot;, views.likes, name=&quot;likes&quot;),
  ]
  </code></pre>
  <p>When I try to access Post url I expect json response to be shown on mostly blank page. Should it be like that? How can I get my API working?</p>