0

管理/コマンドでモデルをインポートしているときに、このトレースバックを受け取りました。

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/vagrant/.virtualenvs/rsspainter/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
    utility.execute()
  File "/home/vagrant/.virtualenvs/rsspainter/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/vagrant/.virtualenvs/rsspainter/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/home/vagrant/.virtualenvs/rsspainter/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/home/vagrant/.virtualenvs/rsspainter/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/vagrant/rsspainter/apps/account/management/commands/create_users.py", line 5, in <module>
    from models import *
  File "/vagrant/rsspainter/apps/account/models.py", line 5, in <module>
    class SeoUser(models.Model):
  File "/home/vagrant/.virtualenvs/rsspainter/local/lib/python2.7/site-packages/django/db/models/base.py", line 93, in __new__
    kwargs = {"app_label": model_module.__name__.split('.')[-2]}
  IndexError: list index out of range

どうしたの??Django 管理ページはうまく機能します。
私のモデル:

class SeoUser(models.Model):
    '''
    Model of user.
    '''

    SEX = (
        ('M', 'Male'),
        ('F', 'Female'),
    )
    THEME_CHOICES = (
        ('auto', u'Автомобили'),
        ('tourism', u'Туризм'),
        ('cooking', u'Готовка'),
        ('gambling', u'Гэмблинг'),
        ('games', u'Онлайн игры'),
        ('business', u'Бизнесс'),
        ('amusement', u'Развлечения'),
        ('sports', u'Спорт и здоровье'),
        ('nyan', u'Животные'),
        ('quotes', u'Цитатники'),
        ('humor', u'Юмор'),
        ('women', u'Женские секреты'),
    )
    name = models.CharField("Name", max_length=100, blank=False)
    surname = models.CharField("Surname",max_length=150, blank=False)
    password = models.CharField("Password", max_length=16)
    country = models.CharField("Country", max_length=25)
    town = models.CharField("Town", max_length=35)
    is_real = models.BooleanField("Real user", default=False)
    sex = models.CharField("Sex", max_length=1, choices=SEX)
    age = models.IntegerField("Age", blank=False)
    thematics = models.CharField("Specification", max_length=15, choices=THEME_CHOICES, default='amusement')

    def __unicode__(self):
        return "%s-%s" % (self.name, self.thematics)
    # links to related models
    def email_count(self):
        return self.email.count()
    email_count.short_description = 'Email accounts'

    def blog_count(self):
        return self.blog.count()
    blog_count.short_description = 'Blogs'

    def twitter_count(self):
        return self.twitter.count()
    twitter_count.short_description = 'Twitter accounts'
4

1 に答える 1

1

モデルがパッケージの一部であることを期待するトップレベルのモジュールを Django に与えました。エラーは、Django がパッケージ名を探した結果であり、ここには存在しません。

models.pyファイルが存在するパッケージを PYTHONPATH に追加しないでください。親パッケージが存在するディレクトリのみをここに追加しますProject/apps

于 2013-11-12T12:04:52.940 に答える