gpt4 book ai didi

python - django.core.exceptions.ImproperlyConfigured : Requested setting USE_I18N, 但未配置设置

转载 作者:太空狗 更新时间:2023-10-29 20:15:04 30 4
gpt4 key购买 nike

我想将 MySQL 数据库连接到我的 django 项目,但它抛出一个错误:

"django.core.exceptions.ImproperlyConfigured: Requested setting USE_I18N, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings."

跟踪:

 (myenv) LIBINGLADWINs-MacBook-Air:libinrenold$ django-admin dbshell
Traceback (most recent call last):
File "/Users/libinrenold/Desktop/djangoworks/myenv/bin/django-admin", line 11, in <module>
sys.exit(execute_from_command_line())
File "/Users/libinrenold/Desktop/djangoworks/myenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Users/libinrenold/Desktop/djangoworks/myenv/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/libinrenold/Desktop/djangoworks/myenv/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/libinrenold/Desktop/djangoworks/myenv/lib/python3.6/site-packages/django/core/management/base.py", line 322, in execute
saved_locale = translation.get_language()
File "/Users/libinrenold/Desktop/djangoworks/myenv/lib/python3.6/site-packages/django/utils/translation/__init__.py", line 195, in get_language
return _trans.get_language()
File "/Users/libinrenold/Desktop/djangoworks/myenv/lib/python3.6/site-packages/django/utils/translation/__init__.py", line 59, in __getattr__
if settings.USE_I18N:
File "/Users/libinrenold/Desktop/djangoworks/myenv/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/Users/libinrenold/Desktop/djangoworks/myenv/lib/python3.6/site-packages/django/conf/__init__.py", line 39, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting USE_I18N, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

设置.py

  DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test',
'USER': 'user',
'PASSWORD': 'root',
'HOST':'',
'PORT': '',
}
}

最佳答案

您必须定义相关变量以显示您的 settings.py 在哪里文件生活:

export DJANGO_SETTINGS_MODULE=mysite.settings

这是相关的docs条目:

When you use Django, you have to tell it which settings you’re using.Do this by using an environment variable, DJANGO_SETTINGS_MODULE.

The value of DJANGO_SETTINGS_MODULE should be in Python path syntax,e.g. mysite.settings. Note that the settings module should be on thePython import search path.

如果您使用的是 virtualenv (这是最好的做法),你可以粘贴相关的export文件中的命令 <path-to-virtualenv>/bin/activate

关于python - django.core.exceptions.ImproperlyConfigured : Requested setting USE_I18N, 但未配置设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47700347/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com