繁体   English   中英

Django 1.8引发错误:django.core.exceptions.AppRegistryNotReady:应用尚未加载

[英]Django 1.8 throws an error: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet

此问题没有完美的解释,可以请任何人解释为什么会引发此错误

Traceback (most recent call last):
  File "manage.py", line 17, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 324, in execute
    django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 90, in create
    module = import_module(entry)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/ubuntu/project-root/DjangoWebProject5/app/views.py", line 11, in <module>
    from app.models import *
  File "/home/ubuntu/project-root/DjangoWebProject5/app/models.py", line 11, in <module>
    class Document(models.Model):
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py", line 94, in __new__
    app_config = apps.get_containing_app_config(module)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 239, in get_containing_app_config
    self.check_apps_ready()
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 124, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet

编辑1个 设置 。pyINSTALLED_APPS

INSTALLED_APPS = (
    'app',
    'app.views',
    #'bootstrap3_datetime',
    'djcelery',
    'kombu.transport.django',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)

项目结构:

Djangowebproject
                 -->Djangowebproject-->settings.py
                                    -->urls.py
                                    -->wsgi.py
                                    -->__init__.py
                 -->app-->migrations
                       -->static
                       -->templates
                       -->templatetags
                       -->admin.py
                       -->forms.py
                       -->models.py
                       -->urls.py
                       -->views.py

app / models.py就像

from django.db import models
from django.db.models import Sum

import datetime


class Document(models.Model):
    title = models.CharField(max_length=200, default='')  # title of the post
    news = models.TextField(default='')  # body of the news
    image = models.FileField(upload_to='documents/%d/%m/%Y', default='')  # image file included in it
    link = models.CharField(max_length=500, default='')  # video file url if present
    pubdate = models.DateTimeField("Date", default=datetime.datetime.now())  # this is date of scrapping
    approvedflag = models.CharField(max_length=200, default='-1')  # approved or not -1 for not and 1 for approved
    publishedfrom = models.CharField(max_length=100, default='')  # this includes domain of page eg: twitter, greatandhra
    type = models.CharField(max_length=100, default='direct post')  # published author for future use
    approvedby = models.CharField(max_length=200, default='')   # user name of the approved person
    parse_objectid = models.CharField(max_length=200, default='')   # unique id response
    source = models.CharField(max_length=200, default='')   # page/post link


class fb_pages_sync(models.Model):
    pagename = models.CharField(max_length=500, default='')
    sync_flag = models.CharField(max_length=2, default='-1')
    status_run = models.CharField(max_length=2, default='-1')
    src_pages = models.CharField(max_length=2,
                                 default='f')  # flag bit to know about whether the pages are form facebook or twitter
    verfied = models.CharField(max_length=2, default='-1')


class Poll(models.Model):
    """A poll object for use in the application views and repository."""
    text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')

    def total_votes(self):
        """Calculates the total number of votes for this poll."""
        return self.choice_set.aggregate(Sum('votes'))['votes__sum']

    def __unicode__(self):
        """Returns a string representation of a poll."""
        return self.text


class Choice(models.Model):
    """A poll choice object for use in the application views and repository."""
    poll = models.ForeignKey(Poll)
    text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)

    def votes_percentage(self):
        """Calculates the percentage of votes for this choice."""
        total = self.poll.total_votes()
        return self.votes / float(total) * 100 if total > 0 else 0

    def __unicode__(self):
        """Returns a string representation of a choice."""
        return self.text

安装的应用程序应仅包含要包含在应用程序中的django应用程序,我看到您已添加了app和app.views。 views不是一个应用程序,它是应用程序目录中存在的python文件,请删除该文件并尝试迁移。

另外,请为最佳实践在django的默认应用程序之后添加自定义应用程序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM