1👍
✅
You need to have that variable inside settings.py
(almost anywhere). Like:
STRIPE_SECRET_KEY = "asQEfg92mf-Wafoi#k9"
But it’s much better idea to store in your environment variables, i.e. in System configuration or in ‘env’ file.
PS there is safer way to get values from settings. Instead of:
stripe.api_key = settings.STRIPE_SECRET_KEY
Use:
stripe.api_key = getattr(settings, "STRIPE_SECRET_KEY", "")
Then there might be warmer warning if there is missing variable, i.e.:
if not stripe.api_key:
print("Hey! 'stripe.api_key is missing!'")
Source:stackexchange.com