from flask import Flask
from flask_dynamo import Dynamo
import os
os.environ['AWS_ACCESS_KEY_ID'] = ''
os.environ['AWS_SECRET_ACCESS_KEY'] = ''
os.environ['AWS_REGION'] = 'ap-south-1'
app = Flask(__name__)
app.config['DYNAMO_TABLES'] = [
{
'TableName': 'users',
'KeySchema': [dict(AttributeName='username', KeyType='HASH')],
'AttributeDefinitions': [dict(AttributeName='username', AttributeType='S')],
'ProvisionedThroughput': dict(ReadCapacityUnits=5, WriteCapacityUnits=5)
}, {
'TableName': 'groups',
'KeySchema': [dict(AttributeName='name', KeyType='HASH')],
'AttributeDefinitions': [dict(AttributeName='name', AttributeType='S')],
'ProvisionedThroughput': dict(ReadCapacityUnits=5, WriteCapacityUnits=5)
}
]
app.config['DYNAMO_ENABLE_LOCAL'] = True
app.config['DYNAMO_LOCAL_HOST'] = 'localhost'
app.config['DYNAMO_LOCAL_PORT'] = 9000
dynamo = Dynamo()
已定义了flask-dynamo的表配置并创建了dynamo实例,当我尝试获取create all tables get error of builtins.AttributeError AttributeError:'Dynamo'对象没有属性'tables'
@app.route('/', methods=['GET'])
def hello_world():
with app.app_context():
dynamo.create_all()
return 'table created!'
环境
python3 烧瓶-发电机
提前致谢
答案 0 :(得分:1)
这一行:
dynamo = Dynamo()
应该是:
dynamo = Dynamo(app)
这样,dynamo实例可以访问您在app对象上定义的表和其他配置。