django.core.exceptions.ImproperlyConfigured: Requested setting CACHES error solution

error message

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.
insert image description here

Problem Description

Today, this problem occurred when Django integrated Redis. The prompt message roughly means that the corresponding configuration item in setting.py cannot be found, but the strange thing is that I have already configured it, so why can’t it be accounted for?
After reading a blogger's post, the reasons are summarized as follows:

Reason: django-redis has been installed, and the CACHES information is configured in the Setting.py configuration file, but the Django configuration file is not loaded in when testing

Solution

这个解决办法也是下下策吧,就是手动加载配置文件

The specific operation is as follows:
insert image description here
打码部分为项目名

 os.environ.setdefault('DJANGO_SETTINGS_MODULE', '你的项目名.settings')

Reference blog
post blog post link

problem solved! ! !

Guess you like

Origin blog.csdn.net/qq_46034741/article/details/129665851