in /instance/app.cfg I've configured :
test=test
In my flask file app.py :
with app.open_instance_resource('app.cfg') as f:
config = f.read()
print('config' , type(config))
Which prints config <class 'bytes'>
Reading the flask doc it does not detail how to read values from configuration files, how is this achieved ?
can config be read a dictionary instead of bytes ?
Update :
app.py :
# Shamelessly copied from http://flask.pocoo.org/docs/quickstart/
from flask import Flask
app = Flask(__name__)
import os
ac = app.config.from_pyfile(os.path.join('.', 'conf/api.conf'), silent=True)
logging_configuration = app.config.get('LOGGING')
if ac:
print(logging.config.dictConfig(ac))
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run()
api.conf :
myvar=tester
returns error :
/./conf/api.conf", line 1, in <module>
myvar=tester
NameError: name 'tester' is not defined
Update 2 :
app.py :
from flask import Flask
app = Flask(__name__)
import os
from logging.config import dictConfig
app.config.from_pyfile(os.path.join('.', 'conf/api.conf'), silent=True)
logging_configuration = app.config.get('LOGGING')
if logging_configuration:
print(dictConfig(logging_configuration))
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.run()
api.conf :
LOGGING="tester"
returns error :
ValueError: dictionary update sequence element #0 has length 1; 2 is required