如何在django shell中打印设置的内容?

时间:2022-01-17 20:32:30

When I run python manage.py shell, I can print out the python path

当我运行python管理时。py shell,我可以输出python路径

>>> import sys
>>> sys.path

What should I type to introspect all my django settings ?

我应该输入什么来反省我的django设置?

4 个解决方案

#1


35  

from django.conf import settings
dir(settings)

and then choose attribute from what dir(settings) have shown you to say:

然后从dir(设置)显示的内容中选择属性:

settings.name

where name is the attribute that is of your interest

你感兴趣的属性在哪里

Alternatively:

另外:

settings.__dict__

prints all the settings. But it prints also the module standard attributes, which may somewhat clutter the output.

打印所有的设置。但是它也打印模块标准属性,这可能会使输出变得混乱。

#2


31  

I know that this is an old question, but with current versions of django (1.6+), you can accomplish this from the command line the following way:

我知道这是一个老问题,但是在当前版本的django(1.6+)中,您可以通过以下方式完成以下命令:

python manage.py diffsettings --all

The result will show all of the settings including the defautls (denoted by ### in front of the settings name).

结果将显示所有的设置,包括defautls(在设置名前面用###表示)。

#3


14  

To show all django settings (including default settings not specified in your local settings file):

显示所有django设置(包括本地设置文件中未指定的默认设置):

from django.conf import settings
dir(settings)

#4


14  

In case a newbie stumbles upon this question wanting to be spoon fed the way to print out the values for all settings:

如果一个新手遇到这个问题,想要用勺式喂食的方式打印出所有设置的值:

def show_settings():
    from django.conf import settings
    for name in dir(settings):
        print name, getattr(settings, name)

#1


35  

from django.conf import settings
dir(settings)

and then choose attribute from what dir(settings) have shown you to say:

然后从dir(设置)显示的内容中选择属性:

settings.name

where name is the attribute that is of your interest

你感兴趣的属性在哪里

Alternatively:

另外:

settings.__dict__

prints all the settings. But it prints also the module standard attributes, which may somewhat clutter the output.

打印所有的设置。但是它也打印模块标准属性,这可能会使输出变得混乱。

#2


31  

I know that this is an old question, but with current versions of django (1.6+), you can accomplish this from the command line the following way:

我知道这是一个老问题,但是在当前版本的django(1.6+)中,您可以通过以下方式完成以下命令:

python manage.py diffsettings --all

The result will show all of the settings including the defautls (denoted by ### in front of the settings name).

结果将显示所有的设置,包括defautls(在设置名前面用###表示)。

#3


14  

To show all django settings (including default settings not specified in your local settings file):

显示所有django设置(包括本地设置文件中未指定的默认设置):

from django.conf import settings
dir(settings)

#4


14  

In case a newbie stumbles upon this question wanting to be spoon fed the way to print out the values for all settings:

如果一个新手遇到这个问题,想要用勺式喂食的方式打印出所有设置的值:

def show_settings():
    from django.conf import settings
    for name in dir(settings):
        print name, getattr(settings, name)