Skip to content
Advertisement

My settings.py file in Django is getting too long. How do I split it into two?

How do I do that? split up 2 files?

Advertisement

Answer

Although my solution is not as complex as the ones above, they fit my simple needs: I have some imports in my settings.py file:

try:
    from settings_local import *
except ImportError:
    pass

try:
    from settings_production import *
except ImportError:
    pass

And then I have a settings_local.py file in my local development folder (which I don’t upload to the server) and where I overwrite local settings. Then I have a settings_production.py server where I keep settings needed for the production environment.

You can use this technique to import other settings files as well.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement