“布尔”对象没有属性“has_header”;通过我的管理员中的文件字段上传时
我的 models.py
from django.db import models
from django.contrib.auth.models import User
class Song(models.Model):
uploader = models.ForeignKey(User)
date_uploaded = models.DateTimeField(auto_now=True)
song_file = models.FileField(upload_to='music/', max_length=100)
artist = models.CharField(max_length=75, blank=True)
title = models.CharField(max_length=100, blank=True)
genre = models.CharField(max_length=100, blank=True)
def __unicode__(self):
return u'%s' % (self.song_file)
我的 admin.py
from django.contrib import admin
from uploader.models import Song
from django.db import models
class SongAdmin(admin.ModelAdmin):
list_display = ('song_file', 'title', 'artist', 'genre', 'uploader')
search_fields = ('song_file', 'uploader', 'genre', 'title')
fields = ('song_file', 'title', 'artist', 'genre')
admin.site.register(Song, SongAdmin)
文件已上传(我在媒体文件夹中看到它),但它没有显示在我的管理页面中,当文件上传时,我得到:
'bool' object has no attribute 'has_header' when uploading via a FileField in my admin
我在这里遗漏了一些明显的东西吗?对 django 来说还很陌生。
My models.py
from django.db import models
from django.contrib.auth.models import User
class Song(models.Model):
uploader = models.ForeignKey(User)
date_uploaded = models.DateTimeField(auto_now=True)
song_file = models.FileField(upload_to='music/', max_length=100)
artist = models.CharField(max_length=75, blank=True)
title = models.CharField(max_length=100, blank=True)
genre = models.CharField(max_length=100, blank=True)
def __unicode__(self):
return u'%s' % (self.song_file)
My admin.py
from django.contrib import admin
from uploader.models import Song
from django.db import models
class SongAdmin(admin.ModelAdmin):
list_display = ('song_file', 'title', 'artist', 'genre', 'uploader')
search_fields = ('song_file', 'uploader', 'genre', 'title')
fields = ('song_file', 'title', 'artist', 'genre')
admin.site.register(Song, SongAdmin)
The file gets uploaded (I see it in my media folder) but it doesnt display in my admin page and when the file does get uploaded I get:
'bool' object has no attribute 'has_header' when uploading via a FileField in my admin
Am I missing something obvious here? Pretty new to django.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明这是 Pinax 的问题。更新到最新的 git,现在一切正常了!
Turns out it was an issue with Pinax. Updated to the latest git and everything works now!
像这样注释掉该中间件,可能应该将该中间件保留在非调试环境中
在网络上的其他地方找到了这个,问题出在 HideSensitiveFieldsMiddleware 中,解决它的方法(用于调试)是在设置文件中
Found this somewhere else on the net, the problem is in the HideSensitiveFieldsMiddleware and the way to work around it (for debug) is to just comment out that middleware like so
in your settings file, probably should leave that middleware in for non debug environments