Приложения еще не загружены
Я использую Visual Studio 2022 в качестве IDE. В ней есть 2 проекта:
- CLI - приложение на Python
- Common - пустой проект Django
Классы создаются в файле Common > app > models.py.
.
app
- это Django app
CLI
- это стартовый проект, а cli.py
- его стартовый файл.
На проект Common
ссылаются в CLI
.
Когда я запускаю приложение CLI в режиме отладки, возникает ошибка для класса Question
.
Стек вызовов:
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.
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.