如何解决此问题?我不确定这是什么意思。
文件“ /Users/kritikasingh/Desktop/Bucketlist/app/init.py”,行 13,在create_app中 app.config.from_object(app_config [config_name])TypeError:“模块”对象没有属性“ getitem ”
这是表明问题所在的代码
def create_app(config_name):
from app.models import Bucketlist
app = FlaskAPI(__name__, instance_relative_config=True)
app.config.from_object(app_config[config_name])
app.config.from_pyfile('config.py')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db.init_app(app)
@app.route('bucketlists/', methods=['POST', 'GET'])
def bucketlists():
if request.method == "POST":
name = str(request.data.get('name', ''))
if name:
bucketlist = Bucketlist(name=name)
bucketlist.save()
response = jsonify({
'id': bucketlist.id,
'name': bucketlist.name,
'date_created': bucketlist.date_created,
'date_modified': bucketlist.date_modified
})
response.status_code = 201
return response
else:
#GET
bucketlists = Bucketlist.get_all()
results = []
for bucketlist in bucketlists:
obj = {
'id': bucketlist.id,
'name': bucketlist.name,
'date_created': bucketlist.date_created,
'date_modified': bucketlist.date_modified
}
results.append(obj)
response = jsonify(results)
response.status_code = 200
return response
return app
答案 0 :(得分:0)
错误消息指出配置文件有问题。看一下app_config [config_file],您可能会在其中输入错误。看来您想使用方法get_item
,而是在寻找get_item作为某物的属性。
app_config = {...}
app_config.get_item("foo")
您想要的地方
app_config["foo"]
或其他类似内容。搜索文字get_item