[英]How to fix an AttributeError in django?
I am trying to return the list of playlists that are associated with the current logged in user and I get an error saying: AttributeError: 'QuerySet' object has no attribute 'has_header 我试图返回与当前登录用户关联的播放列表列表,但出现错误消息:AttributeError:'QuerySet'对象没有属性'has_header
I have included what I believe are the relevant parts of the code below. 我已经包括了我认为是下面代码的相关部分。 Any advice on how to fix this? 有关如何解决此问题的任何建议?
playlist = UserPlaylist.objects.filter(profile=request.user)
return playlist
class UserProfile(models.Model):
user = models.OneToOneField(User)
def __unicode__(self):
return self.user
def create_user_profile(sender, instance, created, **kwargs):
if created:
UserProfile.objects.create(user=instance)
post_save.connect(create_user_profile, sender=User)
class Playlist(models.Model):
playlist = models.CharField('Playlist', max_length = 2000, null=True, blank=True)
def __unicode__(self):
return self.playlist
class Video(models.Model):
video_url = models.URLField('Link to video', max_length = 200, null=True, blank=True)
def __unicode__(self):
return self.video_url
class UserPlaylist(models.Model):
profile = models.ForeignKey(User)
playlist = models.ForeignKey(Playlist)
def __unicode__(self):
return unicode(self.playlist)
class Videoplaylist(models.Model):
video = models.ForeignKey(Video)
playlist = models.ForeignKey(UserPlaylist)
def __unicode__(self):
return unicode(self.playlist)
I just figured it out...I'm doing return instead of print. 我只是想通了...我正在做退货而不是打印。 Rookie mistake. 新秀错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.