简体   繁体   中英

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

I have included what I believe are the relevant parts of the code below. Any advice on how to fix this?

views.py

playlist = UserPlaylist.objects.filter(profile=request.user)
return playlist

models.py

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM