如果我想使用額外的文件中的一些模型,我的Django項目,我不能這樣簡單的方式做到這一點:如何在Django項目中的額外模塊中正確導入模型?
from myproject_app.models import *
,因爲我得到這個錯誤:
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
爲了解決這個問題,我發現這個解決方案:
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
django.setup()
from myproject_app.models import *
好的。有用。但是,如果我想在models.py項目中使用這個額外文件中的任何功能,則根本無法啓動!
請幫幫我。
添加您的setting.py代碼 – badiya
您需要展示如何運行這個「額外的文件」。 –