作者:我想飞 | 来源:互联网 | 2023-06-02 16:47
此错误很容易重现。基本上,只需启动一个新的django项目并使用django-admin运行服务器。我阅读了许多StackOverflow帖子,并尝试了多种方法,但是没有用。以下是复制的详细步骤:
- 创建了名为
testproject
的新目录
-
pipenv install django
- 使用django启动项目脚本启动名为
test
的新项目
-
pipenv shell
-
django-admin runserver
- 错误:
"django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG,but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings."
- 按照django官方文档中的建议,在ubuntu中输入以下内容:
export DJANGO_SETTINGS_MODULE=test.settings
-
django-admin runserver
- 出现了一条巨大的错误行,后跟
ModuleNotFoundError: No module named 'test'
。但是,如果我执行django-admin runserver --pythOnpath=. --settings="test.settings"
,则服务器将成功运行。
我知道我只能使用python manage.py来启动服务器,但是我的项目使用Django缓存框架,当我尝试访问缓存时,会引发相同的settings are not configured
错误。试图了解正在发生的事情,任何帮助将不胜感激。
在您的列表中,我没有看到虚拟环境激活。
您激活了虚拟环境吗?
'''
源激活测试项目
'''