Python/Django - Avoid saving passwords in source code

前端 未结 4 498
悲&欢浪女
悲&欢浪女 2021-01-29 23:44

I use Python and Django to create web applications, which we store in source control. The way Django is normally set up, the passwords are in plain text within the settings.py f

4条回答
  •  悲哀的现实
    2021-01-30 00:24

    This is an old question and the person who asked I'm sure has found a way to deal with this, but I was looking this up myself and figured since the answers here weren't quite the solution I was looking for I might add what I did for any other people potentially asking the same question.

    What I did was use getpass() to have the settings file ask for the password when run at startup.

    from getpass import getpass
    
    #[...]
    
        DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql', #or whatever DB you use
            'NAME': 'mydb',
            'USER': 'myuser',
            'PASSWORD': getpass(),
            'HOST': '',
            'PORT': '',
        }
    }
    

提交回复
热议问题