django.core.exceptions.AppRegistryNotReady:尚未加载应用程序。当我导入模型

时间:2018-05-16 18:37:50

标签: python django django-models anaconda

我也是新的python也是Django。我知道在这个论坛上发布了同样的问题。但仍然无法弄明白。创建了一个模型,需要导入我的views.py文件,以便我可以渲染我的数据。

这是我的views.py

from  first_app.models import Topic, webpage, AccessRecord 
from django.shortcuts import render
from django.http import HttpResponse

# from django.apps import AppConfig

    # Create your views here.
    def index(request): 
        webpage_list = AccessRecord.objects.order_by('date')
        date_dict = {'acess_records': webpage_list}
        return render(request, 'first_app/index.html')

它向我显示了这个错误

PS E:\python\firstp\first_project> python manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x0000024518AB58C8>
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\commands\runserver.py", line 112, in inner_run
    autoreload.raise_last_exception()
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 248, in raise_last_exception
    raise _exception[1]
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\core\management\__init__.py", line 327, in execute
    autoreload.check_errors(django.setup)()
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\apps\registry.py", line 89, in populate
    app_config = AppConfig.create(entry)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\apps\config.py", line 90, in create
    module = import_module(entry)
  File "C:\ProgramData\Anaconda3\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "E:\python\firstp\first_project\first_app\models.py", line 4, in <module>
    class Topic(models.Model):
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\db\models\base.py", line 100, in __new__
    app_config = apps.get_containing_app_config(module)
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\apps\registry.py", line 244, in get_containing_app_config
    self.check_apps_ready()
  File "C:\ProgramData\Anaconda3\lib\site-packages\django\apps\registry.py", line 127, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

我在之前的帖子中尝试过很多东西,但仍然没有进展。 github repository

1 个答案:

答案 0 :(得分:0)

您实际上忘了注册您的应用,转到settings.py,您会看到一个名为INSTALLED_APPS的列表,添加您应用的名称first_appMore info can be found here

INSTALLED_APPS = [
    #names,
    'first_app',
]