samedi 9 août 2014

python - django acces le réglage donné en--argument paramètres sur runserver au programme - Stack Overflow


I often run my django development server with different settings given as parameter as shown in the example below:


python manage.py runserver --settings=my_project.settings.andi

But sometimes it is .andi and sometimes something .other.


How to make universal import statement, which will be able to access this settings always?




TO make clear how it works, and answer to the suggestion Santosh Ghimire: I have base.py which I import in any other (e.g andi) with statetment from .base import * The way to access the things, which are extra added in andi is the one proposed by bruno desthuilliers, i.e with: from django.conf import settings




If your question is "how do my django apps modules know which settings to import", the answer is simply to replace any import settings with from django.conf import settings.




Why don't you separate these different settings in separate files like settings_local.py and settings_remote.py and import each one on necessity in the main settings.py file that holds all the common settings.


This way you won't have to give optional parameters in the runserver command.



I often run my django development server with different settings given as parameter as shown in the example below:


python manage.py runserver --settings=my_project.settings.andi

But sometimes it is .andi and sometimes something .other.


How to make universal import statement, which will be able to access this settings always?




TO make clear how it works, and answer to the suggestion Santosh Ghimire: I have base.py which I import in any other (e.g andi) with statetment from .base import * The way to access the things, which are extra added in andi is the one proposed by bruno desthuilliers, i.e with: from django.conf import settings



If your question is "how do my django apps modules know which settings to import", the answer is simply to replace any import settings with from django.conf import settings.



Why don't you separate these different settings in separate files like settings_local.py and settings_remote.py and import each one on necessity in the main settings.py file that holds all the common settings.


This way you won't have to give optional parameters in the runserver command.


0 commentaires:

Enregistrer un commentaire