(correction) If you run python manage.py shell, settings.py will be in the specified state, so it is better to use this. The following was a wasteful act.
======== Sometimes I want to import Django modules and see help and dir. At that time, if you do it normally, an import error will occur and the module cannot be loaded.
In [1]: import django.shortcuts
(...)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
In order to import it, you need to tell the module that describes the settings in the environment variable DJANGO_SETTINGS_MODULE. By default, you can specify settings.py directly under the Django project.
In [2]: import os
In [3]: os.environ['DJANGO_SETTINGS_MODULE'] = 'mokumoku.settings'
In [4]: import django.shortcuts
In [5]: help(django.shortcuts)
========
Recommended Posts