【问题标题】:How to fix an AttributeError in django?如何修复 Django 中的 AttributeError?
【发布时间】:2012-10-17 17:10:39
【问题描述】:

我正在尝试返回与当前登录用户关联的播放列表列表,但我收到一条错误消息: AttributeError: 'QuerySet' 对象没有属性 'has_header

我已经包含了我认为是下面代码的相关部分。有关如何解决此问题的任何建议?

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)

【问题讨论】:

  • 能否发布错误的完整回溯?
  • 发布全视图功能。就目前而言是错误的。它不返回 HttpResponse。

标签: python django view model


【解决方案1】:

我刚刚想通了...我正在返回而不是打印。菜鸟失误。

【讨论】:

    猜你喜欢
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-13
    • 1970-01-01
    • 1970-01-01
    • 2019-07-19
    相关资源
    最近更新 更多