I have a Python Flask app that accesses the Github API. For this I need to store an access token. What is the common practice to store that data and how do I access that inside my app?
from flask import Flask, request
app = Flask(__name__)
app.config['DEBUG'] = True
@app.route('/',methods=['POST'])
def foo():
...
Command-line: Similarly, the FLASK_ENV variable sets the environment on which we want our flask application to run. For example, if we put FLASK_ENV=development the environment will be switched to development. By default, the environment is set to development.
Flask has a custom context to store app variables:
http://flask.pocoo.org/docs/1.0/appcontext/
You can use g object to store your variables:
from flask import g
g.github_token = 'secret'
And after initialization:
from flask import g
token = g.github_token
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With