问题描述
我刚刚卸载了python 3.6,并安装了python 3.7,然后在将django安装到虚拟环境中,然后键入django-admin时,出现了此错误。
Note that only Django core commands are listed as settings are not properly configured(error: 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.).
然后当我尝试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.
1楼
从Django文档中:
使用Django时,必须告诉它所使用的设置。 通过使用环境变量DJANGO_SETTINGS_MODULE来执行此操作。
DJANGO_SETTINGS_MODULE的值应采用Python路径语法,例如mysite.settings 。 请注意,设置模块应位于Python导入搜索路径上。
示例(Windows Shell):
set DJANGO_SETTINGS_MODULE=mysite.settings
django-admin runserver
请参考以获取更多信息。
2楼
使用manage.py
代替django-admin
更容易,因为manage.py
会为您设置DJANGO_SETTINGS_MODULE
。
使用django-admin
启动项目:
django-admin startproject myproject
但是之后,请改用manage.py
,例如
python manage.py makemigrations
python manage.py migrate
python manage.py runserver