栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python中关于sqlite3数据库删除数据的使用

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python中关于sqlite3数据库删除数据的使用

1.文件结构:

2.使用的数据库可视化工具DB Browser for sqlite下载:

http://www.sqlitebrowser.org/

3.使用DB Browser for sqlite新建表users.db:


图片放置位置:

4.主main.py文件:
import os
import sqlite3 as lite
from flask import Flask,jsonify,render_template,request,abort,redirect,url_for

app=Flask(__name__)
mysql_path=os.path.join(os.getcwd(),'users.db')
#自定义错误
@app.errorhandler(404)
def get_Error_Handel(error):
    return render_template('404.html'),404

@app.route('/',methods=['POST','GET'])
def delete(user):
    conn=lite.connect(mysql_path)
    with conn:
        cur=conn.cursor()
        sql=f"select count(user) from users where user='{user}'"
        cur.execute(sql)
        count=cur.fetchone()[0]
        if count<=0:
            return jsonify('delete user mistake!'),404
        else:
            sql=f"delete from users where user='{user}'"
            cur.execute(sql)
            return render_template('success.html')

@app.route('/delete',methods=['POST','GET'])
def delete_user():
    if request.method=='POST':
        user=request.form.get('username')
        return redirect(url_for('delete',user=user))
    if request.method=='GET':
        return render_template('delete.html')

if __name__ == '__main__':
    app.run(debug=True)
5.delete.html文件:



    
    Delete
    


    

6.错误提示404.html文件:



    
    Failure
    


    
python中关于sqlite3数据库删除数据的使用
7.成功删除的页面success.html:



    
    Success Accept
    



    
python中关于sqlite3数据库删除数据的使用
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/767055.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号