将Django与zinni一起使用时出现taggit导入错误

2024-06-07 05:03:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个django应用程序,我正在尝试使用django-taggit和zinnia blog,下面是我的设置和代码

目录结构

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

本地_设置.py

^{pr2}$

塔吉特_自定义.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而不是{},并尝试使用taggit, 因此,pip install django-taggit安装了taggit

但是当我尝试像上面那样使用taggit应用程序时,它显示了下面的错误

注意:没有从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时,为什么会显示错误呢?在


Tags: appsdjangoinfrompyimportapp应用程序