一、项目的settings.py文件添加下列内容:
# Braintree settings BRAINTREE_MERCHANT_ID = '保密' BRAINTREE_PUBLIC_KEY = '保密' BRAINTREE_PRIVATE_KEY = '保密' from braintree import Configuration, Environment Configuration.configure( Environment.parse_environment("sandbox"), # 这一句重点,千万別写成 Environment.Sandbox # Environment.parse_environment("product"), BRAINTREE_MERCHANT_ID, BRAINTREE_PUBLIC_KEY, BRAINTREE_PRIVATE_KEY )
二、Environment.parse_environment("sandbox"), 这一句重点,千万別写成 Environment.Sandbox ,
原因如下:
1、ctrl+鼠标左键点击上面代码的configure(参数1,参数2,参数3,参数4),会发现 参数1 要填 environment,
2、为了找到 environment ,
ctrl+鼠标左键点击上面代码的Environment,
会发现类Environment里的函数 def parse_environment(environment), 返回值是 Environment.All[environment],
正好 Environment.All["sandbox"] = Environment.Sandbox
@staticmethod def parse_environment(environment): if isinstance(environment, Environment) or environment is None: return environment try: return Environment.All[environment] # ...............................
#........................................ Environment.All = { "development": Environment.Development, "integration": Environment.Development, "qa": Environment.QA, "sandbox": Environment.Sandbox, "production": Environment.Production }