You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure()

django 在vscode的中调试时出现的环境问题配置

  1. 错误信息提示未配置安装应用,django的环境配置文件是manage.py文件,查看文件发现文件中含有if __name__ = __main__,这个文件肯定是有备用供程序当模块使用的功能
>>> from blog.models import Person
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, 
but settings are not configured. You must either define the environment variable
 DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
  1. 解决方法:
    • 直接在解释器中引入manage.py,调用main()函数,配置环境及安装APP
     >>> import manage       
     >>> manage.main()
    
    自动完成配置信息
  2. 成功在解释器中导入模型调试
>>> from blog.models import Person
>>>

python verson 3.7
django verson 3.0

你可能感兴趣的:(python,django,django,python)