字段'id'需要一个数字,但在django中得到了''

mm9b1k5b  于 2022-11-26  发布在  Go
关注(0)|答案(1)|浏览(128)

无法获取blog_id。请帮助我解决此问题---models.py

class Blog(models.Model):
    title = models.CharField(max_length=500)
    body = models.TextField()
    last_updated_on = models.DateTimeField(auto_now=True)
    created_on = models.DateTimeField(auto_now_add=True)
    author_instance = models.ForeignKey(AuthorInstance, on_delete=models.PROTECT)
    status_draft = models.BooleanField(default=False, blank=True, null=True)
    status_publish = models.BooleanField(default=False, blank=True, null=True)
    likes = models.ManyToManyField(UserInstance, related_name='like', default=None, blank=True)
    like_count = models.BigIntegerField(default='0')

    def total_likes(self):
        return self.likes.count()

一月一日

def like_post(request):
    post = get_object_or_404(Blog, id=request.POST.get('blog_id'))

如何解决????

mnowg1ta

mnowg1ta1#

观点应该像

def like_post(request,id):
    post = get_object_or_404(Blog, id=request.POST.get('blog_id'))

相关问题