我在Mac OS X 10.8.2和Python 2.7.2上使用django版本1.5c1
我在model.py
文件中定义了以下模型:
class MyFile(models.Model):
filename = models.FileField(upload_to = '%Y/%m/%d')
并通过将以下行添加到admin.py
文件中将其注册到自动管理界面:
class FileAdmin(admin.ModelAdmin):
list_display = ('filename',)
fields = ('filename',)
admin.site.register(MyFile, FileAdmin)
使用admin webinterface将新的File
对象添加到数据库时,我总是收到以下错误消息:
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/admin/mytest/myfile/add/
Django Version: 1.5c1
Python Version: 2.7.2
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'registry',
'mytest')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
115. response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in wrapper
372. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view
91. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
89. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in inner
202. return view(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapper
25. return bound_func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view
91. response = view_func(request, *args, **kwargs)
File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in bound_func
21. return func(self, *args2, **kwargs2)
File "/Library/Python/2.7/site-packages/django/db/transaction.py" in inner
208. return func(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in add_view
1009. self.log_addition(request, new_object)
File "/Library/Python/2.7/site-packages/django/contrib/admin/options.py" in log_addition
530. action_flag = ADDITION
File "/Library/Python/2.7/site-packages/django/contrib/admin/models.py" in log_action
18. e = self.model(None, None, user_id, content_type_id, smart_text(object_id), object_repr[:200], action_flag, change_message)
Exception Type: TypeError at /admin/mytest/myfile/add/
Exception Value: 'FieldFile' object is not subscriptable
文件保存在正确的位置,但数据库中没有添加任何内容。有关如何解释此'FieldFile' object is not subscriptable
错误消息的任何线索?
亲切的问候, 汉斯