我正在尝试使用Flask和SQLAlchemy扩展程序创建一个用于从数据库中删除记录的函数。问题是,它不仅删除了一行,而是将所有行都删除了。请问我的代码有什么问题?
@app.route('/admin/delete/<int:page_id>', methods=['GET','POST'])
@requires_auth
def delete_page(page_id):
page = Page.query.get(page_id)
if not page:
abort(404)
if page.children:
flash('You can not delete a page with child pages. Delete them, or assign them a different parent.',
'error')
return redirect(url_for('admin_page'))
if request.method == 'POST':
Page.query.get(page_id).query.delete()
db.session.commit()
flash('Page was deleted successfully', 'success')
return redirect(url_for('admin_page'))
return render_template('admin_delete.html', page_title=page.title, page_id=page_id)
提前致谢!
AttributeError: 'Page' object has no attribute 'delete'
。 - Tom Brunoli