[英]taggit import error when using django with zinnia
I have a django app in which i am trying to use django-taggit
and zinnia blog, below are my settings and code我有一个 django 应用程序,我试图在其中使用django-taggit
和django-taggit
博客,下面是我的设置和代码
directory structure目录结构
test_app
apps
app_one
__init__.py
views.py
forms.py
urls.py
models
taggit_custom.py
app_two
settings
local_settings.py
manage.py
local_settings.py local_settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'south',
'taggit',
'zinnia',
)
taggit_custom.py taggit_custom.py
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.conf import settings
from taggit.models import TaggedItem
class CustomModel_one(models.Model):
......
......
So from the above i am trying to use django-zinnia-blog
for my site as blog, but i want to use django-taggit
instead of tagging
, and just given a try to use taggit
, so installed taggit by pip install django-taggit
所以从上面我试图使用django-zinnia-blog
作为我的网站作为博客,但我想使用django-taggit
而不是tagging
,并且只是尝试使用taggit
,所以通过pip install django-taggit
But when i tried to use the taggit application as above like from taggit.models import TaggedItem
its displaying the below error但是当我尝试使用上面的 taggit 应用程序时,比如from taggit.models import TaggedItem
它显示以下错误
Note: Infact no imports from taggit module like注意:事实上没有从 taggit 模块导入,比如
from taggit.models import TaggedItem
from taggit.managers import TaggableManager
from taggit.forms........ etc.,
are working even though the application is installed(Also checked by pip freeze
and taggit is there :))即使安装了应用程序也能正常工作(还通过pip freeze
和 taggit 进行检查:))
result结果
Validating models...
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x9902e8c>>
Traceback (most recent call last):
File "/home/user/Envs/zinnia/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 92, in inner_run
self.validate(display_num_errors=True
......
......
File "/home/user/name/virtualenvironment/apps/test_app/models/taggit_custom.py", line 4, in <module>
from taggit.models import TaggedItem
ImportError: No module named models
So can anyone please let me know why taggit importing is not working even though taggit has been installed ?那么任何人都可以让我知道为什么即使安装了 taggit 也无法导入 taggit 吗?
Edited已编辑
Also when i tried something like below此外,当我尝试类似下面的内容时
(Inside virtual env) (在虚拟环境中)
import taggit
print dir(taggit.models)
result结果
['Aggregate', 'AutoField', 'Avg', 'BLANK_CHOICE_DASH', 'BLANK_CHOICE_NONE', 'BigIntegerField', 'BooleanField', 'CASCADE', 'CharField', 'CommaSeparatedIntegerField', 'Count', 'DO_NOTHING', 'DateField', 'DateTimeField', 'DecimalField', 'DictWrapper', 'EmailField', 'F', 'Field', 'FieldDoesNotExist', 'FileField', 'FilePathField', 'FloatField', 'ForeignKey', 'GenericIPAddressField', 'IPAddressField', 'ImageField', 'ImproperlyConfigured', 'IntegerField', 'Manager', 'ManyToManyField', 'ManyToManyRel', 'ManyToOneRel', 'Max', 'Min', 'Model', 'NOT_PROVIDED', 'NullBooleanField', 'ObjectDoesNotExist', 'OneToOneField', 'OneToOneRel', 'PROTECT', 'PositiveIntegerField', 'PositiveSmallIntegerField', 'ProtectedError', 'Q', 'QueryWrapper', 'SET', 'SET_DEFAULT', 'SET_NULL', 'SlugField', 'SmallIntegerField', 'StdDev', 'SubfieldBase', 'Sum', 'TextField', 'TimeField', 'URLField', 'Variance', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'aggregates', 'base', 'capfirst', 'clean_ipv6_address', 'connection', 'constants', 'copy', 'curry', 'datetime', 'decimal', 'deletion', 'exceptions', 'expressions', 'fields', 'force_text', 'forms', 'get_app', 'get_apps', 'get_model', 'get_models', 'is_iterator', 'loading', 'manager', 'math', 'options', 'parse_date', 'parse_datetime', 'parse_time', 'permalink', 'proxy', 'query', 'query_utils', 'register_models', 'related', 'settings', 'signals', 'six', 'smart_text', 'sql', 'tee', 'timezone', 'total_ordering', 'unicode_literals', 'validators', 'warnings', 'wraps']
so from the above whether taggit is working/installed ?所以从上面 taggit 是否正在工作/安装? and but why its showing an error when i tried from taggit.models import TaggedItem
?但是为什么当我尝试from taggit.models import TaggedItem
时显示错误?
I know it's a 7 year old thread.我知道这是一个 7 岁的线程。 But I'm sharing my experience for the future purpose, someone might be benefited from it.但我是为了将来的目的分享我的经验,有人可能会从中受益。 I've just faced similar problem.我刚刚遇到了类似的问题。 I installed django-taggit (current version is 1.3.0) in my venv.我在我的 venv 中安装了django-taggit (当前版本是 1.3.0)。 I added it to INSTALLED_APPS .我将它添加到INSTALLED_APPS 。 Later on I tried to import in my models.py .后来我尝试导入我的models.py 。 But it was showing import error.但它显示导入错误。 I restarted my VSCode .我重新启动了我的VSCode 。 After a couple of minutes, like 1-2 minutes, it was fixed automatically.几分钟后,比如 1-2 分钟,它会自动修复。 IDK, it was weird. IDK,这很奇怪。 Maybe it needs some time to get working.也许需要一些时间才能开始工作。
So, if you installed it correctly (in the right env) then it should work.因此,如果您正确安装了它(在正确的环境中),那么它应该可以工作。 Just give it some time, maybe restart your IDE and try again.给它一些时间,也许重新启动您的 IDE 并重试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.