TypeError:remove()只取1个参数(给定2个)

时间:2017-11-22 10:58:40

标签: 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("ok.html")

当我通过执行类似“localhost / remove / 1”的操作将参数传递给url时出现以下错误 类型错误

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

我真的无法理解这里的问题我只指定了一个参数而且我正在传递它。

这是我的requirements.txt文件:

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

JECT

1 个答案:

答案 0 :(得分:0)

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

  

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

db.session.remove(PAGE)

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

浏览文档here

您想要使用的是删除/刷新/关闭。删除不带任何参数