ASN

Notes by Akhil Saji

Instituting Local and Production Django Settings files

If you do any of your dynamic web development in Django, maintaining separate settings files for your production and development environments is essential. Here I will detail my setup for this process.

1. Create two files called settings_local.py and settings_production.py for your development environment and production environment respectively.

2. In both files, put in the respective Django settings you need. For example in development you might be using SQLite3 as your database but in production you would use PostgreSQL and therefore the database settings would be different.

3. Next, in your settings.py put in the following code

try:
        from settings_local import *
except ImportError:
        try:
                from settings_server import *
        except ImportError:
                pass

4. Finally, ensure that your settings_local.py is excluded from your source management system (i.e git), so when you push your app to the server, only settings_server.py will get pushed. This step is absolutely essential because the code above will always load the local settings as default if available.


Success

We are what we repeatedly do. Excellence then, is not an act but a habit. -Aristotle