Deleting rows from database with python flask?

前端 未结 4 919
一整个雨季
一整个雨季 2021-01-01 05:58

I am using a flask framework, and can\'t seem to delete rows from the database. The code below gives a 405 error: \"The method is not allowed for the requested URL.\" Any id

4条回答
  •  既然无缘
    2021-01-01 06:40

    I used flaskr as a base for my Flask project (as it looks like you did as well).

    In the .py:

    @app.route('/delete', methods=['POST'])
    def delete_entry():
    if not session.get('logged_in'):
        abort(401)
    g.db.execute('delete from entries where id = ?', [request.form['entry_id']])
    g.db.commit()
    flash('Entry deleted')
    return redirect(url_for('show_entries'))
    

    In the HTML:

    I wanted a button, but you could easily use a link with the solution here.

提交回复
热议问题