Configuration. dev vs production

    I do not think that this topic should be a revelation for advanced Django encoders. But from experience in different projects, I can say that many programmers are still off topic.

    So, any project (practically) requires a separate configuration for the development machine and the production server. You can simply make two configuration files, but sometimes you need to enter and change the settings common to each configuration.

    Some insert a bunch of ifs or something worse, relying on ip (sniff) or the name of the machine, but this is all very inconvenient and clutters up the configuration. For me, this is a very strong argument for not participating in the project, as this indicates the quality of the entire code.

    The Django community has already adopted tacit standards based on the experience of many: creating a separate local_settings.py configuration file and including it at the end of the main configuration, thus overwriting the values ​​of the necessary parameters.

    I think it's better to demonstrate.

    settings.py Next, create local_settings.py and write: Immediately add local_settings.py to svn: ignore, so as not to deal with this in the future. All is ready. We load the project in svn, do svn co / var / svn on production (well, or whatever). Now, without much crap, you can deploy the version from SVN, while the developer has enough space for maneuver in the local configuration. It is simple but extremely convenient. Use who did not know yet.
    # Конфигурация продакшн сервера (БД)
    DATABASE_ENGINE = 'postgresql_psycopg2'
    DATABASE_NAME = 'professors'
    DATABASE_USER = 'root'
    DATABASE_PASSWORD = 'blabla'
    DATABASE_HOST = 'localhost'
    DATABASE_PORT = ''
    # Тут всякая прочая бредятина
    # ...
    # А вот тут включаем
    try:
        from local_settings import *
    except ImportError:
        pass


    DATABASE_ENGINE = 'postgresql_psycopg2'
    DATABASE_NAME = 'professors_v2'
    DATABASE_USER = 'developer'
    DATABASE_PASSWORD = 'blabla2'







    Related Links


    Also popular now: