想单独启动调试单个py文件,从pycharm启动单独py程序 ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
2 回答
蝴蝶不菲
TA贡献1810条经验 获得超4个赞
需要再单独文件的头部上添加
import sysimport ossys.path.append('/Users/nooper/Documents/work/payment/')os.environ['DJANGO_SETTINGS_MODULE']="payment.settings"
这里settings就是项目包程序的配置的settings. 需要项目的工作路径引入进来。
森栏
TA贡献1810条经验 获得超5个赞
Pycharm debug django问题
报错:
django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
解决:配置一下 run/edit configuration,注意我第二个红色覆盖掉的只setting所在的模块,比如你可能settings是在mysite模块下,那就写mysite.settings
2.如果之前已经在terminal里runserver 了,先把他们关掉
3.开始debug,出现下面这样的情况就OK了!
添加回答
举报
0/150
提交
取消