TypeError:“module”对象没有属性“\uu getitem”,tdd restful api

2024-10-05 13:06:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我该如何着手解决这个问题?我不知道这是什么意思。在

File "/Users/kritikasingh/Desktop/Bucketlist/app/init.py", line 13, in create_app app.config.from_object(app_config[config_name]) TypeError: 'module' object has no attribute '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

Tags: namefromidconfigappdatereturnobject
1条回答
网友
1楼 · 发布于 2024-10-05 13:06:46

错误消息指出配置文件有问题。看看app峎u config[config_file]你可能有个打字错误。看起来您希望使用方法get_item,而是将get_item作为某个属性来查找。在

app_config = {...}
app_config.get_item("foo")

你想去哪里

^{pr2}$

或者其他类似的东西。搜索文本get_item

相关问题 更多 >

    热门问题