我是Django和Python的新手。初始化Django設置中的自定義對象
我在我的應用程序根目錄下創建了一個名爲services.py的python文件。在這個文件裏我有一個名爲SchedulerService的類。我正嘗試在設置模塊中初始化SchedulerService的一個實例,以便每次執行視圖時都可以使用該實例。在Java世界中,我將使用單例對象並使用自動init servlet或MBean對其進行初始化。
我遇到的問題是我無法將任何自定義模塊導入到settings.py文件中。例如:
settings.py
from theapp.services import SchedulerService
我收到以下消息時,我嘗試啓動我的開發服務器
Error: Can't find the file 'settings.py' in the directory containing 'manage.py'. It appears you've customized things.
You'll have to run django-admin.py, passing it your settings module.
(If the file settings.py does indeed exist, it's causing an ImportError somehow.)
我得到同樣的錯誤,如果我嘗試導入視圖或模型類放入設置模塊中。
也許我正在做的完全錯誤,應該以另一種方式實施。
任何幫助將不勝感激。
這是你懷疑的循環依賴 – user578888