Python TypeError:remove()只接受1个参数(给定2个)

Python TypeError:remove()只接受1个参数(给定2个),python,python-2.7,flask,Python,Python 2.7,Flask,我正在编写代码来删除给定id的页面 @app.route("/remove/<int:id>",methods=['POST','GET']) @login_required def remove(id): PAGE=MY_DAIRY.query.get(id) db.session.remove(PAGE) db.session.commit() flash("done deleting ") return render_template("

我正在编写代码来删除给定id的页面

@app.route("/remove/<int:id>",methods=['POST','GET'])
@login_required
def remove(id):
    PAGE=MY_DAIRY.query.get(id)
    db.session.remove(PAGE)
    db.session.commit()
    flash("done deleting ")
    return render_template("ok.html")
我真的不明白这里的问题是什么,我只指定了一个参数,我正在传递它

这是我的requirements.txt文件:

整个回溯:


ject

您的错误是由于sqlachemy会话删除函数调用引起的

文件“/home/nidhal/Bureau/diaryy/app.py”,第144行,删除

db.session.remove(PAGE)

TypeError: remove() takes exactly 1 argument (2 given)
浏览文档


您要使用的可能是delete/flush/close。remove不接受任何参数

您确定错误是由于路由函数而非会话remove函数引起的。您可以发布堆栈跟踪而不是一行错误欢迎使用堆栈溢出!你能回答这个问题,让我们看看这个函数的调用吗。事实上,我们真的需要一个新的话题,否则这个问题很可能会因为离题而被关闭。您还可以确认引发错误的是哪一行(是调用此函数还是调用
db.session.remove
?)我认为您将self留在函数中作为参数否是调用函数db.session remove很好什么是
db
?您使用的是pymongo吗?谢谢,我以为这是因为名为remove的路线
Flask==0.12.2 ,Flask-Bootstrap==3.0.3.1, Flask-SQLAlchemy==1.0
Flask-WTF==0.9.4 ,Jinja2==2.7.1, SQLAlchemy==0.8.4 ,WTForms==1.0.5
Werkzeug==0.9.6, Flask-Login==0.4.0
    File "/home/nidhal/.local/lib/python2.7/site-packages/flask/app.py", line 1997, in __call__

    return self.wsgi_app(environ, start_response)

    File "/home/nidhal/.local/lib/python2.7/site-packages/flask/app.py", line 1985, in wsgi_app

    response = self.handle_exception(e)

    File "/home/nidhal/.local/lib/python2.7/site-packages/flask/app.py", line 1540, in handle_exception

    reraise(exc_type, exc_value, tb)

    File "/home/nidhal/.local/lib/python2.7/site-packages/flask/app.py", line 1982, in wsgi_app

    response = self.full_dispatch_request()

    File "/home/nidhal/.local/lib/python2.7/site-packages/flask/app.py", line 1614, in full_dispatch_request

    rv = self.handle_user_exception(e)

    File "/home/nidhal/.local/lib/python2.7/site-packages/flask/app.py", line 1517, in handle_user_exception

    reraise(exc_type, exc_value, tb)

    File "/home/nidhal/.local/lib/python2.7/site-packages/flask/app.py", line 1612, in full_dispatch_request

    rv = self.dispatch_request()

    File "/home/nidhal/.local/lib/python2.7/site-packages/flask/app.py", line 1598, in dispatch_request

    return self.view_functions[rule.endpoint](**req.view_args)

    File "/home/nidhal/.local/lib/python2.7/site-packages/flask_login/utils.py", line 228, in decorated_view

    return func(*args, **kwargs)

    File "/home/nidhal/Bureau/diaryy/app.py", line 144, in remove

    db.session.remove(PAGE)

    TypeError: remove() takes exactly 1 argument (2 given)

The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.

To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

    dump() shows all variables in the frame
    dump(obj) dumps all that's known about the ob
db.session.remove(PAGE)

TypeError: remove() takes exactly 1 argument (2 given)