gpt4 book ai didi

python-3.x - Flask Dynamo 连接问题(AttributeError : 'Dynamo' object has no attribute 'tables' )

转载 作者:行者123 更新时间:2023-12-03 16:51:52 26 4
gpt4 key购买 nike

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 发电机的表配置并创建了发电机实例,当我尝试获取创建所有表时出现 的错误builtins.AttributeError AttributeError: 'Dynamo' 对象没有属性 'tables'
@app.route('/', methods=['GET'])
def hello_world():
with app.app_context():
dynamo.create_all()
return 'table created!'

环境

python3 flask-dynamo



提前致谢

最佳答案

这一行:

dynamo = Dynamo()

应该:
dynamo = Dynamo(app)

这样,发电机实例可以访问您在应用程序对象上定义的表和其他配置。

关于python-3.x - Flask Dynamo 连接问题(AttributeError : 'Dynamo' object has no attribute 'tables' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46111203/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com