1

我有一个非常简单的 CRUD API:

from bottle import get, post, put, delete, run

@get('/items/')
@get('/items')
def item_list():
    return "LIST"

@get('/items/<upc>')
def item_show( upc="0000" ):
    return "SHOW ITEM WITH UPC " + upc

@delete('/items/<upc>')
def item_delete( upc="0000" ):
    return "DELETE ITEM WITH UPC " + upc

@put('/items/<upc>')
def item_save( upc="0000" ):
    return "SAVE ITEM WITH UPC " + upc

@post('/items/<upc>')
def item_create( upc="0000" ):
    return "CREATE ITEM WITH UPC " + upc

run()

这很好用,我可以运行服务器并点击所有端点并取回正确的字符串。但如果我添加:

from sqlalchemy import *

到顶部然后当我尝试运行服务器时出现此错误:

Traceback (most recent call last):
  File "app.py", line 14, in <module>
    def item_delete( upc="0000" ):
TypeError: 'Delete' object is not callable

我究竟做错了什么?

4

1 回答 1

2

我的猜测是,sqlalchemy它的名称delete覆盖了from bottle import delete.

您可以通过仅执行或仅从(例如) import sqlalchemy导入所需的功能来解决此问题。sqlalchemyfrom sqlalchemy import function_you_need, object_you_need

于 2012-08-01T23:46:02.667 回答