I can't see any serious problems with that solution, no, and if you're happy with it then you can safely go ahead doing things that way.
But things might get more complicated if you want to have other things that differ between the different environments. For example, in PythonAnywhere itself -- our front-end is a Django application -- the live site has not only different database settings, but different PayPal API keys, Stripe keys, email addresses, and so on. And if you use a big "if" statement to contain the different bits, it could become unmanageable.
Django developers have heated debates about what the "best" way to handle that kind of thing is. A popular solution, however, is to have multiple settings files. Instead of having a settings.py
file, you'd have a directory called settings
in the same location. In that directory, you'd have a file called __init__.py
that looked like this:
from .common_settings import *
from .local_settings import *
You would also have files there called dev_settings.py
and prod_settings.py
, which would contain the specific settings for those environments, and common_settings.py
to hold (of course) the stuff that was common to all environments.
The final step is the local_settings.py
file, also in the settings
directory. If you're using git, this one would be in your .gitignore
file and would be something you'd create when you check out the repository. (If you're not using git, it's just a file.)
It would just import stuff from whichever environment file you wanted to use for that code tree -- for example, for production, it would be:
from .prod_settings import *
Hope that helps!