Python ImportError:无法导入通用名称
我正在django 1.9中使用eav django(实体属性值)。每当我执行命令Python ImportError:无法导入通用名称,python,django,generics,django-1.9,Python,Django,Generics,Django 1.9,我正在django 1.9中使用eav django(实体属性值)。每当我执行命令/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/
/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
在models.py中。经过几次研究之后,我发现泛型在Django1.7中已经被弃用了,而在Django1.9中已经不存在了。有谁能告诉我Django 1.9中添加了哪些其他库以及如何使用该功能吗?Django.contrib.contenttypes模块已经安装 现在可以使用
django.contrib.contenttypes.generic.GenericForeignKey
而不是django.contrib.contenttypes.fields.GenericForeignKey
。请参见文档中的示例代码:
此功能已移动到.models和.fields模块中。
只是删除了特定的文件;泛型关系功能仍然存在,只是被分割成单独的文件。从Python的官方网站更新Django.tagging包,而不是从Pip源代码,因为Pip没有最新版本。您能建议如何使用eav django吗?您需要修改
django eav
源代码,并将所有generic.GenericForeignKey
替换为字段.GenericForeignKey
。在我的例子中,我的项目使用Python3,而我忘记了启用虚拟环境。因此标准python(2.7)给出了这个错误。我真傻!你能建议如何使用eav django吗??
from django.contrib.contenttypes import generic