I tried my best to proceed according to this site, but to delete it, I used sweetalert to make sure it was deleted But it didn't happen The problem is that by clicking on the delete option, we must first get the user's id, then go to the delete page, but before deleting the line, use sweetalert. How?
@app.route('/pythonlogin/delete', methods =['GET'])
def delete():
if 'loggedin' in session:
deleteuser = request.args.get('userid')
conn = mysql.connect()
cur = conn.cursor(pymysql.cursors.DictCursor)
cur.execute('DELETE FROM accounts WHERE userid= %s', (deleteuser, ))
conn.commit()
return redirect(url_for('User_management', userid=deleteuser))
<td><a id ="delete" href="{{url_for('User_management', userid=user.userid)}}" class="btn btn-primary">delete</a></td>`
<script>
$('a#delete').click(function () {
var url = $(this).attr('href');
var arguments = url.split('?')[1].split('=');
arguments.shift();
Swal.fire({
title: 'آیا مطمئن هستید؟',
text: "کاربر پاک شده غیر قابل بازگشت است",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'بله پاک کن',
cancelButtonText: 'انصراف'
})
.then((result) => {
if (result.isConfirmed) {
location ="{{url_for('delete',userid = arguments)}}"
}
else{location ="{{url_for('User_management',userid = arguments)}}"}
})
});
</script>
I found the solution A third page called getid is required
main.python
User_managment.html