admin管理员组

文章数量:1400043

I'm using Visual Studio 2022 as the IDE. It has 2 projects:

  1. CLI - A Python Application
  2. Common - A Blank Django Project

The classes are created in Common > app > models.py.
app is a Django app

CLI is the startup project, and cli.py is its startup file.
Common project is referenced in CLI.

When I Start the CLI app in debug mode, there is an error for the Question class.

Call Stack:

 Message=Apps aren't loaded yet.  
 Source=D:\Projects\Internal\LLRT\src\Common\app\models.py  
 StackTrace:   File
 "D:\Projects\Internal\LLRT\src\Common\app\models.py", line 4, in
 <module> (Current frame)
     q_id = models.IntegerField()
     ...<7 lines>...
     correct_option_num = models.IntegerField()   File "D:\Projects\Internal\LLRT\src\CLI\cli.py", line 4, in <module>
>     from app.models import Option, Question, Answered_Question django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

I'm using Visual Studio 2022 as the IDE. It has 2 projects:

  1. CLI - A Python Application
  2. Common - A Blank Django Project

The classes are created in Common > app > models.py.
app is a Django app

CLI is the startup project, and cli.py is its startup file.
Common project is referenced in CLI.

When I Start the CLI app in debug mode, there is an error for the Question class.

Call Stack:

 Message=Apps aren't loaded yet.  
 Source=D:\Projects\Internal\LLRT\src\Common\app\models.py  
 StackTrace:   File
 "D:\Projects\Internal\LLRT\src\Common\app\models.py", line 4, in
 <module> (Current frame)
     q_id = models.IntegerField()
     ...<7 lines>...
     correct_option_num = models.IntegerField()   File "D:\Projects\Internal\LLRT\src\CLI\cli.py", line 4, in <module>
>     from app.models import Option, Question, Answered_Question django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Share Improve this question edited Mar 25 at 11:18 sukesh asked Mar 25 at 8:49 sukeshsukesh 2,41112 gold badges64 silver badges130 bronze badges 7
  • So what is the actual error? I.e., the full traceback? – 9769953 Commented Mar 25 at 8:52
  • 2 idownvotedbecau.se/imageofcode (to further clarify: the images are barely readable, given their size. And the contrast is not always as good, with all its colored code.) – 9769953 Commented Mar 25 at 8:52
  • @9769953 The error is in the subject Apps aren't loaded yet. I have now added the call stack. Sorry, but why the down vote? The images are very clear. – sukesh Commented Mar 25 at 10:14
  • Did you read the accompanying link? Which mentions among other how images don't allow someone to copy-paste code. Also, "very clear" is subjective: the text is pretty small, and contrast differs per person; with images, I am not able to tweak the contrast, while with normal text, I am. – 9769953 Commented Mar 25 at 10:56
  • Please format tracebacks, code errors and such as code, not as a quote. So that individual lines can be properly distinguished. – 9769953 Commented Mar 25 at 10:57
 |  Show 2 more comments

2 Answers 2

Reset to default 0

Try modify your cli.py to initialize Django first:

import os
import django

Also Make sure your app is properly listed in INSTALLED_APPS in settings.py

I resolved this by adding the statement django.setup().
It works now, but it just looks odd that the statement is in the import statements section.
Please let me know if there is a better way of doing this.

本文标签: python 3xApps aren39t loaded yetStack Overflow