我已经在Heroku上以以下树形结构部署了flask应用程序:
├── app.py
├── config.json
├── payload.json
├── Procfile
├── requirements.txt
我的代码需要从config.json和payload.json读取和写入。但是Heroku不允许以持久方式读写文件。那么,如何在能够读写这两个文件的地方实现S3 bucket或postgres数据库?大多数可用的解决方案都是用于图像上传等。 这是我如何在本地实现的示例代码:
@app.route('/token',methods=['POST'])
def token():
token_payload = json.loads(request.data)
temp = {'token':token_payload['access_token']}
with open('config.json') as json_file:
config = json.load(json_file)
config.update(temp)
write_json(config,'config.json')
return('Token Received')
with open('config.json') as json_file:
config_data = json.load(json_file)
access_token = config_data['token']