ImportError:无法导入名称泛型

时间:2017-07-30 10:55:03

标签: python django elasticsearch django-haystack

我安装了Django 1.10。我需要导入loafing但不能导入它。我正在尝试使用Haystack将我的django应用程序与elasticsearch连接,并希望构建索引。我想要运行的代码是

  

python manage.py rebuild_index

我得到的错误是:

base ---dir
/Manish/Projects/Spark/ad-tracking-django-env/ad-tracking-django
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Manish/Projects/Spark/ad-tracking-django-env/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/Manish/Projects/Spark/ad-tracking-django-env/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
    django.setup()
  File "/Manish/Projects/Spark/ad-tracking-django-env/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Manish/Projects/Spark/ad-tracking-django-env/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/Manish/Projects/Spark/ad-tracking-django-env/lib/python2.7/site-packages/django/apps/config.py", line 199, in import_models
    self.models_module = import_module(models_module_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Manish/Projects/Spark/ad-tracking-django-env/lib/python2.7/site-packages/catalog/models.py", line 4, in <module>
    from django.contrib.contenttypes import generic
ImportError: cannot import name generic

主要错误是:

  

ImportError:无法导入名称通用

1 个答案:

答案 0 :(得分:3)

django 1.9中已删除

loading类,这就是您收到错误的原因。相反,您可以使用apps类。

>>> from django.apps import apps

编辑: v1.9中也删除了generic类,并且功能已移至模型类和字段类。

>>> from django.contrib.contenttypes.models import ContentType
>>> from django.contrib.contenttypes.fields import GenericForeignKey

可以找到更多信息here