使用django和zinnia时的taggit导入错误

时间:2013-08-29 11:17:18

标签: python django tagging django-taggit zinnia

我有一个django应用,我正在尝试使用django-taggit和百日草博客,下面是我的设置和代码

目录结构

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

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

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):
    ......
    ......

因此,从上面我尝试将django-zinnia-blog用于我的网站作为博客,但我想使用django-taggit代替tagging,并尝试使用{{ 1}}, 所以taggit

安装了taggit

但是当我尝试像pip install django-taggit一样使用taggit应用程序时,它会显示以下错误

注意:事实上没有从taggit模块导入,如

from taggit.models import TaggedItem

即使安装了应用程序也正常工作(也由from taggit.models import TaggedItem from taggit.managers import TaggableManager from taggit.forms........ etc., 检查并且taggit在那里:))

结果

pip freeze

所以有人可以告诉我为什么即使已经安装了taggit,taggit导入也无法正常工作?

被修改

当我尝试下面的内容时

(内部虚拟环境)

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

结果

import taggit
print dir(taggit.models)

所以从上面来看taggit是否正在工作/安装? 但是当我尝试['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'] 时,为什么它显示错误?

1 个答案:

答案 0 :(得分:1)

我知道这是7年的老话题。但是我正在分享我的经验,以备将来之用,也许有人会从中受益。 我刚刚面临类似的问题。我在venv中安装了 django-taggit (当前版本为1.3.0)。我将其添加到 INSTALLED_APPS 中。后来我尝试导入我的 models.py 。但是它显示了导入错误。我重新启动了 VSCode 。几分钟后(例如1-2分钟),它会自动修复。 IDK,这很奇怪。也许需要一些时间才能开始工作。

因此,如果您正确安装了它(在正确的环境中),则它应该可以工作。给它一些时间,也许重新启动IDE并再试一次。

相关问题