Reputation: 1930
Is it possible to run my Django project in DEBUG
mode, when in PyCharm? If not in PyCharm, say in production, then of course the DEBUG
mode should not be True
. How can this be done most neatly?
Upvotes: 2
Views: 794
Reputation: 99
Use cookiecutter-duango to generate the project template when starting a new Django project. Your project can be configured for development with PyCharm and you get the both configurations, development (with DEBUG=True) and production (with DEBUG=False) automatically.
Upvotes: 0
Reputation: 174622
Edit your run configuration and set an environment variable called DJANGO_DEBUG
to True
. The easiest way to do this is to create a custom run configuration.
PYTHONUNBUFFERED=1
:Click Apply then OK to dismiss the dialogues.
Edit your settings.py
and add this:
import os
DEBUG = os.environ.get('DJANGO_DEBUG', False)
Now, simply select your new configuration from the Run menu when you want to run with debugging enabled.
Upvotes: 2
Reputation: 72271
The standard approach for this is to have multiple Django settings files:
settings/
base.py
production.py
development.py
testing.py
then you can run DJANGO_SETTINGS_MODULE=settings.development manage.py runserver
.
PyCharm allows to pick the settings in run configurations too.
Upvotes: 1
Reputation: 169051
The easiest way would probably be setting up your settings.py
to read the DEBUG
value from the environment variables, then tell PyCharm to run with that env var set.
import os
# ...
DEBUG = (True if os.environ.get('DEBUG') else False)
and set DEBUG=1
in PyCharm's Edit Configurations... window.
Upvotes: 3