Hiding secure django settings info on webfaction

前端 未结 2 599
無奈伤痛
無奈伤痛 2021-01-07 12:29

I am trying to hide secure info like database password of a django application on webfaction.
But I could not find how and where to set these infos using environmental v

2条回答
  •  庸人自扰
    2021-01-07 13:04

    I developed a package that you can install with pip:

    pip install djangosecure
    

    And in your settings.py you could use something like:

    import djangosecure
    
    ...
    
    DATABASES = {
        'default': djangosecure.get_database('production'),
    }
    
    ...
    

    The first time you run a manage command you will be prompted for the database information.

    It can be used to secure more settings, see the readme at: https://github.com/rafahsolis/djangosecure

    Update: Updated: djangosecure>=0.0.4 no longer has get_database() function, it now works based on classes so the new ussage would be:

    from djangosecure import DjangoDatabaseSettings
    databases = DjangoDatabaseSettings(os.path.join(PROJECT_ROOT, 'databases.cnf'), 
    crypto_key_file='path/to/your/cryptokey)
    
    DATABASES = {
        'default': 'default': databases.settings('production'),
    }
    

提交回复
热议问题