无法从django中的设置文件中获取设置。

时间:2023-01-13 20:51:26

I've a setting say gi in settings.py file. I've created a separate python file (i.e. I'm not using it in views) and used import statement as:

我在设置中设置了gi。py文件。我创建了一个单独的python文件(例如,我不在视图中使用它),并使用import语句作为:

from django.conf import settings

but when I try to access settings.gi, it says that 'Settings' object has no attribute 'gi'. What's missing? :s

但是当我尝试访问设置时。gi,它说“Settings”对象没有属性“gi”。缺失的是什么?:年代

2 个解决方案

#1


17  

From the Django docs on creating your own settings states:

来自Django关于创建您自己的设置的文档:

Setting names are in all uppercase.

设置名称都是大写的。

Try renaming the setting to GI.

尝试将设置重命名为GI。

#2


0  

The project must be added on the PYTHONPATH and the DJANGO_SETTINGS_MODULE has to be defined. Please refer to the commands mentioned below.

必须在PYTHONPATH上添加项目,并且必须定义DJANGO_SETTINGS_MODULE。请参考下面提到的命令。

export PYTHONPATH=PATH_OF_PROJECT
export DJANGO_SETTINGS_MODULE=settings

#1


17  

From the Django docs on creating your own settings states:

来自Django关于创建您自己的设置的文档:

Setting names are in all uppercase.

设置名称都是大写的。

Try renaming the setting to GI.

尝试将设置重命名为GI。

#2


0  

The project must be added on the PYTHONPATH and the DJANGO_SETTINGS_MODULE has to be defined. Please refer to the commands mentioned below.

必须在PYTHONPATH上添加项目,并且必须定义DJANGO_SETTINGS_MODULE。请参考下面提到的命令。

export PYTHONPATH=PATH_OF_PROJECT
export DJANGO_SETTINGS_MODULE=settings