【发布时间】:2019-12-03 12:16:12
【问题描述】:
背景信息:
我想使用 atom script 插件运行 feeder.py 脚本。我首先遇到了ImproperlyConfigured 错误,已按照此处的建议解决:First fix
然后我遇到RuntimeError: Model class models.AccountInformation doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS. 错误,该错误通过使用模型导入的绝对路径解决,如下所示。
当前问题:
使用提到的绝对导入,我收到此错误:
ModuleNotFoundError: No module named 'Dashboard_app'
我什至可以为该应用程序渲染模板等,所以我很困惑他为什么告诉我该模块不存在。当我删除模型导入时,一切正常。是不是 script 实例无法正确识别?
我的尝试:
- 已删除 + 重新创建
__init__.py - 检查了应用程序的设置以包含在
INSTALLED-APPSdic 中 - 将导入路径更改为
DASHEX.Dashboard_app.models导致no module named DASHEX错误 - 将导入路径更改为
models导致Model class models.AccountInformation doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS错误 - 将
INSTALLED_APPS中的应用更改为Dashboard_app
feeder.py 脚本:
import django
from django.conf import settings
import zmq
import time
from time import sleep
import uuid
settings.configure()
django.setup()
import sys
print(sys.path)
from Dashboard_app.models import AccountInformation
[...]
settings.py:
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
#other Apps
'Wiki_app',
'rest_framework',
'Dashboard_app.apps.DashboardAppConfig'
]
Models.py:
from django.db import models
import uuid
# Create your models here.
class AccountInformation(models.Model):
version = models.CharField(max_length=20, blank=False)
DID = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
accountNumber = models.IntegerField(blank=False)
broker = models.CharField(max_length=50, blank=False)
leverage = models.CharField(max_length=10, blank=False)
account_balance = models.FloatField(max_length=15, blank=False)
account_profit = models.FloatField(max_length=15, blank=False)
account_equity = models.FloatField(max_length=15, blank=False)
account_margin = models.FloatField(max_length=15, blank=False)
account_margin_free = models.FloatField(max_length=15, blank=False)
account_margin_leve = models.FloatField(max_length=15, blank=False)
account_currency = models.CharField(max_length=20, blank=False)
class Meta:
db_table = 'AccountInfo'
def __str__(self):
return self.accountNumber
项目结构:
【问题讨论】: