Here is my solution. Add the code below to the bottom of your settings file.
# Process --set command line option
import sys
# This module can be imported several times,
# check if the option has been retrieved already.
if not hasattr(sys, 'arg_set'):
# Search for the option.
args = filter(lambda arg: arg[:6] == '--set=', sys.argv[1:])
if len(args) > 0:
expr = args[0][6:]
# Remove the option from argument list, because the actual command
# knows nothing about it.
sys.argv.remove(args[0])
else:
# --set is not provided.
expr = ''
# Save option value for future use.
sys.arg_set = expr
# Execute the option value.
exec sys.arg_set
Then just pass any code to any management command:
./manage.py runserver --set="DEBUG=True ; TEMPLATE_DEBUG=True"
python manage.py runserver
called or you have your custom commandpython manage.py foo
and you want to set DEBUG inside it? – Anestassia./manage.py --set="DEBUG=True" runserver
. Maybe the most easy way is to exec a command line parameter value right in settings.py. But I was hoping there is a way to not modify the source code at all. – Debrahdebrecen