gpt4 book ai didi

python - 导入错误 : cannot import name generic

转载 作者:太空狗 更新时间:2023-10-29 17:28:38 24 4
gpt4 key购买 nike

我正在使用 django 1.9 中的 eav-django(entity-attribute-value)。每当我执行命令 ./manage.py runserver 时,我都会收到错误:

Unhandled exception in thread started by <function wrapper at 0x10385b500>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/apps/config.py", line 202, 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 "/Users/shakil_grofers/src/django-eav/eav/models.py", line 42, in <module>
from django.contrib.contenttypes import generic

我试图通过添加导入泛型:

from django.contrib.contenttypes import generic 

在 models.py 中。然后经过一些研究,我发现泛型在 Django 1.7 中已被弃用,在 Django 1.9 中不再存在。谁能告诉我在 Django 1.9 中添加了这个功能的哪个其他库以及如何使用它?

最佳答案

django.contrib.contenttypes 模块已经reorganized in Django 1.7 .

您现在可以使用 django.contrib.contenttypes.fields.GenericForeignKey 而不是 django.contrib.contenttypes.generic.GenericForeignKey。请参阅文档中的示例代码:

https://docs.djangoproject.com/en/1.7/ref/contrib/contenttypes/#generic-relations

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

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