Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local setting for INSTALLED_APPS using Fabric

Tags:

django

fabric

I have an app(django-compressor) that I only want to run on my local machine and not the server. I know about the

try:
    from local_settings import *
except ImportError:
    pass 

trick. But I was wondering if there was a better way to remove the app I only want run locally from the INSTALLED_APPS in the settings.py using Fabric.

like image 700
Alexis Avatar asked Feb 22 '12 09:02

Alexis


2 Answers

I think the standard approach you mentioned is best; create a folder settings with three settings files; shared.py, production.py and development.py. Settings that are common to all instances of your app are placed in shared.py and this is imported from production.py and development.py. Then you can easily only add compressor in your development settings

shared.py

INSTALLED_APPS = (...)

development.py

from settings.shared import *
INSTALLED_APPS += ('compressor',)

You need to make sure then when developing, you run the development server with the development.py settings file:

python manage.py --settings=settings.development 

and similarly on your production server you do the same for production.py (this is down to your implementation)

This is a much better approach in the long term as you can also specify separate cache, database, search etc. settings too.

As an aside, instead of completely removing compressor from your installed apps, you can simply enable and disable is using it's COMPRESS_ENABLED setting

like image 134
Timmy O'Mahony Avatar answered Oct 15 '22 04:10

Timmy O'Mahony


You can also do it in another way.

All the shared settings are in settings.py and keep the difference in local_settings. In your case it is INSTALLED_APPS, you can change your import section to something like this:

DEV_APPS = None
try:
    from local_settings import *
    INSTALLED_APPS += DEV_APPS
except:
    PASS

And here is your local_settings.py:

DEV_APPS = ('compressor',)
like image 6
Zhe Li Avatar answered Oct 15 '22 05:10

Zhe Li