TypeError:__ init __()得到了一个意外的关键字参数'image_field'

时间:2015-06-01 07:23:23

标签: python django

我有诊所的个人资料,并希望为每个人添加图像。我正在尝试使用django-imaging并收到此错误。我按照文档进行了以下操作:

settings.py

INSTALLED_APPS = (
    'm1',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',
    'django.contrib.sitemaps',
    'imaging',

models.py

from imaging.fields import ImagingField

class Clinic(models.Model):
    name = models.CharField(max_length=500)
    slug = models.CharField(max_length=200, unique = True)
    photos = models.ImagingField()

urls.py

url(r'^imaging/', include('imaging.urls')),

然后我尝试了syncdb并收到以下错误:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 284, in execute
    self.validate()
  File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 310, in validate
    num_errors = get_validation_errors(s, app)
  File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors
    self._populate()
  File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 75, in _populate
    self.load_app(app_name, True)
  File "/Library/Python/2.7/site-packages/django/db/models/loading.py", line 99, in load_app
    models = import_module('%s.models' % app_name)
  File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 40, in import_module
    __import__(name)
  File "/Users/harisaghadi/code/meddy Production App/meddy1/models.py", line 10, in <module>
    from imaging.fields import ImagingField
  File "/Library/Python/2.7/site-packages/django_imaging-1.0.0-py2.7.egg/imaging/fields.py", line 6, in <module>
    from imaging.models import Image
  File "/Library/Python/2.7/site-packages/django_imaging-1.0.0-py2.7.egg/imaging/models.py", line 22, in <module>
    class Image(models.Model):
  File "/Library/Python/2.7/site-packages/django_imaging-1.0.0-py2.7.egg/imaging/models.py", line 31, in Image
    options={'quality':90}
TypeError: __init__() got an unexpected keyword argument 'image_field'

2 个答案:

答案 0 :(得分:1)

这是Django Imaging中的一个错误;见issue #11 in their tracker

  

django-imagekit已更新且image_field kwarg已重命名为source,这是django-imaging中的一个错误,需要修复。

2012年12月重命名took place quite some time ago

解决方法是将Django-Imagekit降级到版本2.0.2,最后一个版本的字段仍然命名为image_field。但是,从2年半前开始修复字段重命名的项目可能不值得生产。问题#11是在一年前提交的,并且一直没有修复。

答案 1 :(得分:-1)

在你的models.py中,试试
photos = ImagingField() 而不是 photos = models.ImagingField()

请阅读文档https://github.com/pielgrzym/django-imaging

  

将imagesField从imaging.fields导入添加到所需的模型   ImagingField

     

class Somemodel(models.Model):       photos = ImagingField()