How do I print out the contents of my settings in a django shell?

PythonDjango

Python Problem Overview


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

>>> import sys
>>> sys.path

What should I type to introspect all my django settings ?

Python Solutions


Solution 1 - Python

from django.conf import settings
dir(settings)

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

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.

Solution 2 - Python

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:

python manage.py diffsettings --all

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

Solution 3 - Python

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))

Solution 4 - Python

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

from django.conf import settings
dir(settings)

Solution 5 - Python

In your shell, you can call Django's built-in diffsettings:

from django.core.management.commands import diffsettings

output = diffsettings.Command().handle(default=None, output="hash", all=False)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFrankie RiberyView Question on Stackoverflow
Solution 1 - PythonpajtonView Answer on Stackoverflow
Solution 2 - PythonNoah AbrahamsonView Answer on Stackoverflow
Solution 3 - PythonSkylar SavelandView Answer on Stackoverflow
Solution 4 - PythonVinod KurupView Answer on Stackoverflow
Solution 5 - PythonNick S.View Answer on Stackoverflow