gpt4 book ai didi

python - 导入错误 : cannot import name generic

转载 作者:太空宇宙 更新时间:2023-11-03 15:52:58 25 4
gpt4 key购买 nike

我已经安装了 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: cannot import name generic

最佳答案

loading 类已在 django 1.9 中删除,这就是您收到错误的原因。相反,您可以使用 apps 类。

>>> from django.apps import apps

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

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

可以找到更多信息 here

关于python - 导入错误 : cannot import name generic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45399060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com