目前我正在尝试将SECRET_KEY存储在环境变量中:
# settings/base.py
def get_env_variable(var_name):
""" Get the environment variable or return exception """
try:
return os.environ[var_name]
except KeyError:
error_msg = 'Set the {} environment variable'.format(var_name)
raise ImproperlyConfigured(error_msg)
SECRET_KEY = get_env_variable('SECRET_KEY')
我不知道该如何使用Fabric部署我的项目:
@task
def deploy():
syncdb()
collectstatic()
@task
def collectstatic():
dj('collectstatic')
with cd('{django_root}/static'.format(**env)):
fix_permissions()
@task
def syncdb():
dj('syncdb')
@task
def dj(command):
run('{virtualenv_dir}/bin/python {django_root}/manage.py {dj_command}'.format(dj_command=command, **env))
在这种情况下,设置环境变量的最佳方法是什么? 我真的希望能自动化这个过程,并且可以多次使用此fabscript。同时,我不想将机密信息存储在fabfile或设置中,因为我将把它们推送到公共repo。