ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured.

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. The
django import app reported an error, even if the app and its model.py were previously used, and suddenly Unavailable solution

  • The essential reason is that the
    Python import module is searched according to the path, but the import path is unreachable due to environmental variable problems, that is, the module is not found in the current search path
  • Solution
    Add the path of the module to the search path (os.environ) in files such as view.py
import sys
sys.path.append('../')      # 该模块的路径
import os
import django
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'  # mysite是当前的项目目录名
django.setup()

from testModel.models  import xixi  # 此时导入模块即可成功
...
Published 141 original articles · Like 318 · Visit 270,000+

Guess you like

Origin blog.csdn.net/Sunny_Future/article/details/105538184