我有一个我正在尝试使用的 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
,并且只是尝试使用taggit
,所以安装了 taggitpip install django-taggit
但是当我尝试使用上面的 taggit 应用程序时,from taggit.models import TaggedItem
它会显示以下错误
注意:事实上没有从 taggit 模块导入
from taggit.models import TaggedItem
from taggit.managers import TaggableManager
from taggit.forms........ etc.,
即使安装了应用程序也可以工作(也检查过pip freeze
并且 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
那么任何人都可以让我知道为什么即使安装了 taggit 也无法导入 taggit ?
已编辑
另外,当我尝试以下类似的事情时
(在虚拟环境中)
import taggit
print dir(taggit.models)
结果
['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']
那么从上面是否 taggit 工作/安装?但是为什么当我尝试时它显示错误from taggit.models import TaggedItem
?