In Tornado I want to use base settings.py
file, that import prod_settings.py
and local_settings.py
.
So, the options in that modules can repeat each other. For example, DEBUG=False
in prod_settings and DEBUG=True
in local_settings.
But I have an error
tornado.options.Error: Option 'DEBUG' already defined.
How I understand, I can't define twice the same option.
Why? How to do this?
Thanks!
You can't define an option more than once. You could set a variable DEFAULT_DEBUG
in prod_settings.py
and local_settings.py
and then use that as the default when you call define('DEBUG', default=DEFAULT_DEBUG)
in settings.py
.
But this question suggests that you're going about things in the wrong way. In tornado.options
, the intended pattern is to define the options once in your code, and then the values come from outside the code, via the command line (or config file, but command line is more idiomatic). So you wouldn't have conditional imports of local_settings.py
or prod_settings.py
, but instead you'd have run-local.sh
and run-prod.sh
to pass in the appropriate flags.