About Django Console in PyCharm with Multiple Django Settings

When you have multiple Django settings (for example, for a multi-site project), Django shell in PyCharm doesn't allow you to select the settings and just uses the default project settings.

But you can fix that. Go to:

Preferences...Build, Execution, DeploymentConsoleDjango Console

Then change the content of Starting script:

1
2
3
4
5
6
7
import sys; print('Python %s on %s' % (sys.version, sys.platform))
import django; print('Django %s' % django.get_version())
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
settings_path = input("Enter project settings path")
import os; os.environ["DJANGO_SETTINGS_MODULE"] = settings_path
if 'setup' in dir(django): django.setup()
import django_manage_shell; django_manage_shell.run(PROJECT_ROOT)

Tips and Tricks Programming Developer Experience Django 4.2 Django 3.2 Django 2.2 Python 3 PyCharm