最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python mysql項(xiàng)目實(shí)戰(zhàn)及框架搭建過程

 更新時(shí)間:2021年06月09日 18:26:26   作者:總是幸福的老豌豆  
本文給大家分享python mysql項(xiàng)目實(shí)戰(zhàn)框架搭建過程,通過實(shí)例代碼給大家講解python mysql項(xiàng)目實(shí)戰(zhàn)的相關(guān)知識,需要的朋友參考下吧

前言

python+mysql.connector,demo實(shí)戰(zhàn)

框架搭建

說實(shí)話,其實(shí)沒有使用到框架,只是用了, python+mysql.connector模塊
首先在開始虛擬環(huán)境:

(vega-j-vI5SDr) (vega) D:\test\python-mysql\python-mysql\vega>pip install mysql.connector
Processing c:\users\administrator\appdata\local\pip\cache\wheels\7b\14\39\5aad423666e827dfe9a1fbcd111ac17171e7c9865d570780ce\mysql_connector-2.2.9-cp39-cp39-win_amd64.whl
Installing collected packages: mysql.connector
Successfully installed mysql.connector

在這里插入圖片描述

源代碼地址

代碼實(shí)現(xiàn) 創(chuàng)建mysql連接池

#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Time : 2021/6/6 13:16
# @Author : zhaocunwei
# @Version:V 0.1
# @File : mysql_db.py
# @desc :

import mysql.connector.pooling

__config = {
    "host": "localhost",
    "port": 3306,
    "user": "root",
    "password": "root",
    "database": "vega"
}

try:
    pool = mysql.connector.pooling.MySQLConnectionPool(
        **__config,
        pool_size=10
    )
except Exception as e:
    print(e)

SQL腳本:

/*
Navicat MariaDB Data Transfer

Source Server         : localhost_3306
Source Server Version : 100120
Source Host           : localhost:3306
Source Database       : vega

Target Server Type    : MariaDB
Target Server Version : 100120
File Encoding         : 65001

Date: 2018-11-27 19:35:26
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for t_news
-- ----------------------------
DROP TABLE IF EXISTS `t_news`;
CREATE TABLE `t_news` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(40) NOT NULL,
  `editor_id` int(10) unsigned NOT NULL,
  `type_id` int(10) unsigned NOT NULL,
  `content_id` char(12) NOT NULL,
  `is_top` tinyint(3) unsigned NOT NULL,
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `state` enum('草稿','待審批','已審批','隱藏') NOT NULL,
  PRIMARY KEY (`id`),
  KEY `editor_id` (`editor_id`),
  KEY `type_id` (`type_id`),
  KEY `state` (`state`),
  KEY `create_time` (`create_time`),
  KEY `is_top` (`is_top`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of t_news
-- ----------------------------
INSERT INTO `t_news` VALUES ('1', '新聞標(biāo)題1', '2', '1', '1', '1', '2018-11-22 18:55:56', '2018-11-22 18:55:56', '待審批');

-- ----------------------------
-- Table structure for t_role
-- ----------------------------
DROP TABLE IF EXISTS `t_role`;
CREATE TABLE `t_role` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `role` varchar(20) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `role` (`role`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of t_role
-- ----------------------------
INSERT INTO `t_role` VALUES ('2', '新聞編輯');
INSERT INTO `t_role` VALUES ('1', '管理員');

-- ----------------------------
-- Table structure for t_type
-- ----------------------------
DROP TABLE IF EXISTS `t_type`;
CREATE TABLE `t_type` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `type` varchar(20) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `type` (`type`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of t_type
-- ----------------------------
INSERT INTO `t_type` VALUES ('2', '體育');
INSERT INTO `t_type` VALUES ('5', '歷史');
INSERT INTO `t_type` VALUES ('4', '娛樂');
INSERT INTO `t_type` VALUES ('3', '科技');
INSERT INTO `t_type` VALUES ('1', '要聞');

-- ----------------------------
-- Table structure for t_user
-- ----------------------------
DROP TABLE IF EXISTS `t_user`;
CREATE TABLE `t_user` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(20) NOT NULL,
  `password` varchar(500) NOT NULL,
  `email` varchar(100) NOT NULL,
  `role_id` int(10) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`),
  KEY `username_2` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of t_user
-- ----------------------------
INSERT INTO `t_user` VALUES ('1', 'admin', '3E6BC27A781F0AC08BCFD78CC3DCE4CA', 'admin@163.com', '1');
INSERT INTO `t_user` VALUES ('2', 'scott', '3E6BC27A781F0AC08BCFD78CC3DCE4CA', 'scott@163.com', '1');
INSERT INTO `t_user` VALUES ('3', 'test_1', '3E6BC27A781F0AC08BCFD78CC3DCE4CA', 'test_1@163.com', '2');
INSERT INTO `t_user` VALUES ('4', 'test_2', '3E6BC27A781F0AC08BCFD78CC3DCE4CA', 'test_2@163.com', '2');
INSERT INTO `t_user` VALUES ('5', 'test_3', '3E6BC27A781F0AC08BCFD78CC3DCE4CA', 'test_3@163.com', '2');
INSERT INTO `t_user` VALUES ('6', 'test_4', '3E6BC27A781F0AC08BCFD78CC3DCE4CA', 'test_4@163.com', '2');
INSERT INTO `t_user` VALUES ('7', 'test_5', '3E6BC27A781F0AC08BCFD78CC3DCE4CA', 'test_5@163.com', '2');
INSERT INTO `t_user` VALUES ('8', 'test_6', '3E6BC27A781F0AC08BCFD78CC3DCE4CA', 'test_6@163.com', '2');
INSERT INTO `t_user` VALUES ('9', 'test_7', '3E6BC27A781F0AC08BCFD78CC3DCE4CA', 'test_7@163.com', '2');
INSERT INTO `t_user` VALUES ('10', 'test_8', '3E6BC27A781F0AC08BCFD78CC3DCE4CA', 'test_8@163.com', '2');
INSERT INTO `t_user` VALUES ('11', 'test_9', '3E6BC27A781F0AC08BCFD78CC3DCE4CA', 'test_9@163.com', '2');
INSERT INTO `t_user` VALUES ('12', 'test_10', '3E6BC27A781F0AC08BCFD78CC3DCE4CA', 'test_10@163.com', '2');
INSERT INTO `t_user` VALUES ('13', 'test_11', '3E6BC27A781F0AC08BCFD78CC3DCE4CA', 'test_11@163.com', '2');

創(chuàng)建DAO程序

在這里插入圖片描述

#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Time : 2021/6/6 13:24
# @Author : zhaocunwei
# @Version:V 0.1
# @File : user_dao.py
# @desc : 用戶

from db.mysql_db import pool


class UserDao:
    # 驗(yàn)證用戶登錄
    def login(self, username, password):
        try:
            con = pool.get_connection()
            cursor = con.cursor()
            sql = "SELECT COUNT(*) FROM t_user WHERE username=%s AND " \
                  "AES_DECRYPT(UNHEX(password),'HelloWorld')=%s"
            cursor.execute(sql, (username, password))
            count = cursor.fetchone()[0]
            return True if count == 1 else False
        except Exception as e:
            print(e)
        finally:
            if "con" in dir():
                con.close()

    # 查詢用戶角色
    def search_user_role(self, username):
        try:
            con = pool.get_connection()
            cursor = con.cursor()
            sql = "SELECT r.role FROM t_user u JOIN t_role r ON u.role_id=r.id" \
                  "WHERE u.username=%s"
            cursor.execute(sql, (username))
            role = cursor.fetchone()[0]
            return role
        except Exception as e:
            print(e)
        finally:
            if "con" in dir():
                con.close()

創(chuàng)建service層程序

#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Time : 2021/6/6 13:57
# @Author : zhaocunwei
# @Version:V 0.1
# @File : user_service.py
# @desc :

from db.user_dao import UserDao


class UserService:
    # 創(chuàng)建私有對象
    __user_dao = UserDao()

    # 創(chuàng)建登錄函數(shù)
    def login(self, username, password):
        result = self.__user_dao.login(username, password)
        return result

    # 查詢用戶角色
    def search_user_role(self, username):
        role = self.__user_dao.search_user_role(username)
        return role

安裝變色的模塊,O(∩_∩)O哈哈~

(vega-j-vI5SDr) (vega) D:\test\python-mysql\python-mysql\vega>pip install colorama
Collecting colorama
  Using cached colorama-0.4.4-py2.py3-none-any.whl (16 kB)
Installing collected packages: colorama
Successfully installed colorama-0.4.4

CMD模擬登陸

#!/usr/bin/env python
# _*_ coding: utf-8 _*_
# @Time : 2021/6/6 14:08
# @Author : zhaocunwei
# @Version:V 0.1
# @File : app.py
# @desc : 控制臺程序

from colorama import Fore, Style
from getpass import getpass
from service.user_service import UserService
import os
import sys

__user_service = UserService()

while True:
    os.system("cls")
    print(Fore.LIGHTBLUE_EX, "\n\t=========================")
    print(Fore.LIGHTBLUE_EX, "\n\t歡迎使用新聞管理系統(tǒng)")
    print(Fore.LIGHTBLUE_EX, "\n\t=========================")
    print(Fore.LIGHTGREEN_EX, "\n\t1.登錄系統(tǒng)")
    print(Fore.LIGHTGREEN_EX, "\n\t2.退出系統(tǒng)")
    print(Style.RESET_ALL)
    opt = input("\n\t輸入操作編號:")
    if opt == "1":
        username = input("\n\t用戶名:")
        password = getpass("\n\t密碼:")
        result = __user_service.login(username, password)
        # 登錄成功
        if result == True:
            # 查詢角色
            role = __user_service.search_user_role(username)
            os.system("cls")
            while True:
                if role == "新聞編輯":
                    print("test")
                elif role == "管理員":
                    print(Fore.LIGHTGREEN_EX, "\n\t1.新聞管理")
                    print(Fore.LIGHTGREEN_EX, "\n\t2.用戶管理")
                    print(Fore.LIGHTRED_EX, "\n\tabck.退出登錄")
                    print(Fore.LIGHTRED_Ex, "\n\texit.退出系統(tǒng)")
                    print(Style.RESET_ALL)
                    opt = input("\n\t輸入操作編號:")
        else:
            print("\n\t登錄失敗")
    elif opt == "2":
        sys.exit(0)

在這里插入圖片描述

from db.mysql_db import pool

class NewsDao:
    #查詢待審批新聞列表
    def search_unreview_list(self,page):
        try:
            con=pool.get_connection()
            cursor=con.cursor()
            sql="SELECT n.id,n.title,t.type,u.username " \
                "FROM t_news n JOIN t_type t ON n.type_id=t.id " \
                "JOIN t_user u ON n.editor_id=u.id " \
                "WHERE n.state=%s " \
                "ORDER BY n.create_time DESC " \
                "LIMIT %s,%s"
            cursor.execute(sql,("待審批",(page-1)*10,10))
            result=cursor.fetchall()
            return result
        except Exception as e:
            print(e)
        finally:
            if "con" in dir():
                con.close()

    # 查詢待審批新聞的總頁數(shù)
    def search_unreview_count_page(self):
        try:
            con=pool.get_connection()
            cursor=con.cursor()
            sql="SELECT CEIL(COUNT(*)/10) FROM t_news WHERE state=%s"
            cursor.execute(sql,["待審批"])
            count_page=cursor.fetchone()[0]
            return count_page
        except Exception as e:
            print(e)
        finally:
            if "con" in dir():
                con.close()
    #審批新聞
    def update_unreview_news(self,id):
        try:
            con = pool.get_connection()
            con.start_transaction()
            cursor=con.cursor()
            sql="UPDATE t_news SET state=%s WHERE id=%s"
            cursor.execute(sql,("已審批",id))
            con.commit()
        except Exception as e:
            if "con" in dir():
                con.rollback()
            print(e)
        finally:
            if "con" in dir():
                con.close()




    #查詢新聞列表
    def search_list(self,page):
        try:
            con=pool.get_connection()
            cursor=con.cursor()
            sql="SELECT n.id,n.title,t.type,u.username " \
                "FROM t_news n JOIN t_type t ON n.type_id=t.id " \
                "JOIN t_user u ON n.editor_id=u.id " \
                "ORDER BY n.create_time DESC " \
                "LIMIT %s,%s"
            cursor.execute(sql,((page-1)*10,10))
            result=cursor.fetchall()
            return result
        except Exception as e:
            print(e)
        finally:
            if "con" in dir():
                con.close()

    #查詢新聞總頁數(shù)
    def search_count_page(self):
        try:
            con=pool.get_connection()
            cursor=con.cursor()
            sql="SELECT CEIL(COUNT(*)/10) FROM t_news"
            cursor.execute(sql)
            count_page=cursor.fetchone()[0]
            return count_page
        except Exception as e:
            print(e)
        finally:
            if "con" in dir():
                con.close()

    #刪除新聞
    def delete_by_id(self,id):
        try:
            con = pool.get_connection()
            con.start_transaction()
            cursor=con.cursor()
            sql="DELETE FROM t_news WHERE id=%s"
            cursor.execute(sql,[id])
            con.commit()
        except Exception as e:
            if "con" in dir():
                con.rollback()
            print(e)
        finally:
            if "con" in dir():
                con.close()
from db.news_dao import NewsDao

class NewsService:
    __news_dao=NewsDao()

    # 查詢待審批新聞列表
    def search_unreview_list(self,page):
        result=self.__news_dao.search_unreview_list(page)
        return result

    # 查詢待審批新聞的總頁數(shù)
    def search_unreview_count_page(self):
        count_page=self.__news_dao.search_unreview_count_page()
        return count_page

    # 審批新聞
    def update_unreview_news(self, id):
        self.__news_dao.update_unreview_news(id)

    #查詢新聞列表
    def search_list(self, page):
        result=self.__news_dao.search_list(page)
        return result

    # 查詢新聞總頁數(shù)
    def search_count_page(self):
        count_page=self.__news_dao.search_count_page()
        return count_page

    # 刪除新聞
    def delete_by_id(self, id):
        self.__news_dao.delete_by_id(id)
from colorama import Fore,Style,init
init()
from getpass import getpass
from service.user_service import UserService
from service.news_service import NewsService
from service.role_service import RoleService
import os
import sys
import time


__user_service=UserService()
__news_service=NewsService()
__role_service=RoleService()

while True:
    os.system("cls")
    print(Fore.LIGHTBLUE_EX,"\n\t==================")
    print(Fore.LIGHTBLUE_EX,"\n\t歡迎使用新聞管理系統(tǒng)")
    print(Fore.LIGHTBLUE_EX, "\n\t==================")
    print(Fore.LIGHTGREEN_EX,"\n\t1.登陸系統(tǒng)")
    print(Fore.LIGHTGREEN_EX,"\n\t2.退出系統(tǒng)")
    print(Style.RESET_ALL)
    opt=input("\n\t輸入操作編號:")
    if opt=="1":
        username=input("\n\t用戶名:")
        password=getpass("\n\t密碼:")
        result=__user_service.login(username,password)
        #登陸成功
        if result==True:
            #查詢角色
            role=__user_service.search_user_role(username)
            while True:
                os.system("cls")
                if role=="新聞編輯":
                    print('test')
                elif role=="管理員":
                    print(Fore.LIGHTGREEN_EX,"\n\t1.新聞管理")
                    print(Fore.LIGHTGREEN_EX, "\n\t2.用戶管理")
                    print(Fore.LIGHTRED_EX, "\n\tback.退出登陸")
                    print(Fore.LIGHTRED_EX, "\n\texit.退出系統(tǒng)")
                    print(Style.RESET_ALL)
                    opt = input("\n\t輸入操作編號:")
                    if opt=="1":
                        while True:
                            os.system("cls")
                            print(Fore.LIGHTGREEN_EX, "\n\t1.審批新聞")
                            print(Fore.LIGHTGREEN_EX, "\n\t2.刪除新聞")
                            print(Fore.LIGHTRED_EX, "\n\tback.返回上一層")
                            print(Style.RESET_ALL)
                            opt = input("\n\t輸入操作編號:")
                            if opt=="1":
                                page=1
                                while True:
                                    os.system("cls")
                                    count_page=__news_service.search_unreview_count_page()
                                    result=__news_service.search_unreview_list(page)
                                    for index in range(len(result)):
                                        one=result[index]
                                        print(Fore.LIGHTBLUE_EX, "\n\t%d\t%s\t%s\t%s"%(index+1,one[1],one[2],one[3]))
                                    print(Fore.LIGHTBLUE_EX, "\n\t-------------------")
                                    print(Fore.LIGHTBLUE_EX,"\n\t%d/%d"%(page,count_page))
                                    print(Fore.LIGHTBLUE_EX, "\n\t-------------------")
                                    print(Fore.LIGHTRED_EX, "\n\tback.返回上一層")
                                    print(Fore.LIGHTRED_EX, "\n\tprev.上一頁")
                                    print(Fore.LIGHTRED_EX, "\n\tnext.下一頁")
                                    print(Style.RESET_ALL)
                                    opt = input("\n\t輸入操作編號:")
                                    if opt=="back":
                                        break
                                    elif opt=="prev" and page>1:
                                        page-=1
                                    elif opt=="next" and page<count_page:
                                        page+=1
                                    elif int(opt)>=1 and int(opt)<=10:
                                        news_id=result[int(opt)-1][0]
                                        __news_service.update_unreview_news(news_id)
                            elif opt=="2":
                                page=1
                                while True:
                                    os.system("cls")
                                    count_page=__news_service.search_count_page()
                                    result=__news_service.search_list(page)
                                    for index in range(len(result)):
                                        one=result[index]
                                        print(Fore.LIGHTBLUE_EX, "\n\t%d\t%s\t%s\t%s"%(index+1,one[1],one[2],one[3]))
                                    print(Fore.LIGHTBLUE_EX, "\n\t-------------------")
                                    print(Fore.LIGHTBLUE_EX,"\n\t%d/%d"%(page,count_page))
                                    print(Fore.LIGHTBLUE_EX, "\n\t-------------------")
                                    print(Fore.LIGHTRED_EX, "\n\tback.返回上一層")
                                    print(Fore.LIGHTRED_EX, "\n\tprev.上一頁")
                                    print(Fore.LIGHTRED_EX, "\n\tnext.下一頁")
                                    print(Style.RESET_ALL)
                                    opt = input("\n\t輸入操作編號:")
                                    if opt=="back":
                                        break
                                    elif opt=="prev" and page>1:
                                        page-=1
                                    elif opt=="next" and page<count_page:
                                        page+=1
                                    elif int(opt)>=1 and int(opt)<=10:
                                        news_id=result[int(opt)-1][0]
                                        __news_service.delete_by_id(news_id)
                            elif opt=="back":
                                break
                    elif opt=="2":
                        while True:
                            os.system("cls")
                            print(Fore.LIGHTGREEN_EX, "\n\t1.添加用戶")
                            print(Fore.LIGHTGREEN_EX, "\n\t2.修改用戶")
                            print(Fore.LIGHTGREEN_EX, "\n\t3.刪除用戶")
                            print(Fore.LIGHTRED_EX, "\n\tback.返回上一層")
                            print(Style.RESET_ALL)
                            opt = input("\n\t輸入操作編號:")
                            if opt=="back":
                                break
                            elif opt=="1":
                                os.system("cls")
                                username=input("\n\t用戶名:")
                                password = getpass("\n\t密碼:")
                                repassword=getpass("\n\t重復(fù)密碼:")
                                if password!=repassword:
                                    print("\n\t兩次密碼不一致(3秒自動(dòng)返回)")
                                    time.sleep(3)
                                    continue
                                email=input("\n\t郵箱:")
                                result=__role_service.search_list()
                                for index in range(len(result)):
                                    one=result[index]
                                    print(Fore.LIGHTBLUE_EX,"\n\t%d.%s"%(index+1,one[1]))
                                print(Style.RESET_ALL)
                                opt=input("\n\t角色編號:")
                                role_id=result[int(opt)-1][0]
                                __user_service.insert(username,password,email,role_id)
                                print("\n\t保存成功(3秒自動(dòng)返回)")
                                time.sleep(3)
                            elif opt=="2":
                                page = 1
                                while True:
                                    os.system("cls")
                                    count_page = __user_service.search_count_page()
                                    result = __user_service.search_list(page)
                                    for index in range(len(result)):
                                        one = result[index]
                                        print(Fore.LIGHTBLUE_EX,
                                              "\n\t%d\t%s\t%s" % (index + 1, one[1], one[2]))
                                    print(Fore.LIGHTBLUE_EX, "\n\t-------------------")
                                    print(Fore.LIGHTBLUE_EX, "\n\t%d/%d" % (page, count_page))
                                    print(Fore.LIGHTBLUE_EX, "\n\t-------------------")
                                    print(Fore.LIGHTRED_EX, "\n\tback.返回上一層")
                                    print(Fore.LIGHTRED_EX, "\n\tprev.上一頁")
                                    print(Fore.LIGHTRED_EX, "\n\tnext.下一頁")
                                    print(Style.RESET_ALL)
                                    opt = input("\n\t輸入操作編號:")
                                    if opt == "back":
                                        break
                                    elif opt == "prev" and page > 1:
                                        page -= 1
                                    elif opt == "next" and page < count_page:
                                        page += 1
                                    elif int(opt) >= 1 and int(opt) <= 10:
                                        os.system("cls")
                                        user_id=result[int(opt)-1][0]
                                        username = input("\n\t新用戶名:")
                                        password = getpass("\n\t新密碼:")
                                        repassword = getpass("\n\t再次輸入密碼:")
                                        if password!=repassword:
                                            print(Fore.LIGHTRED_EX,"\n\t兩次密碼不一致(3秒自動(dòng)返回)")
                                            print(Style.RESET_ALL)
                                            time.sleep(3)
                                            break
                                        email = input("\n\t新郵箱:")
                                        result = __role_service.search_list()
                                        for index in range(len(result)):
                                            one = result[index]
                                            print(Fore.LIGHTBLUE_EX, "\n\t%d.%s" % (index + 1, one[1]))
                                        print(Style.RESET_ALL)
                                        opt = input("\n\t角色編號:")
                                        role_id = result[int(opt) - 1][0]
                                        opt=input("\n\t是否保存(Y/N)")
                                        if opt=="Y" or opt=="y":
                                            __user_service.update(user_id,username,password,email,role_id)
                                            print("\n\t保存成功(3秒自動(dòng)返回)")
                                            time.sleep(3)
                            elif opt=="3":
                                page = 1
                                while True:
                                    os.system("cls")
                                    count_page = __user_service.search_count_page()
                                    result = __user_service.search_list(page)
                                    for index in range(len(result)):
                                        one = result[index]
                                        print(Fore.LIGHTBLUE_EX,
                                              "\n\t%d\t%s\t%s" % (index + 1, one[1], one[2]))
                                    print(Fore.LIGHTBLUE_EX, "\n\t-------------------")
                                    print(Fore.LIGHTBLUE_EX, "\n\t%d/%d" % (page, count_page))
                                    print(Fore.LIGHTBLUE_EX, "\n\t-------------------")
                                    print(Fore.LIGHTRED_EX, "\n\tback.返回上一層")
                                    print(Fore.LIGHTRED_EX, "\n\tprev.上一頁")
                                    print(Fore.LIGHTRED_EX, "\n\tnext.下一頁")
                                    print(Style.RESET_ALL)
                                    opt = input("\n\t輸入操作編號:")
                                    if opt == "back":
                                        break
                                    elif opt == "prev" and page > 1:
                                        page -= 1
                                    elif opt == "next" and page < count_page:
                                        page += 1
                                    elif int(opt) >= 1 and int(opt) <= 10:
                                        os.system("cls")
                                        user_id=result[int(opt)-1][0]
                                        __user_service.delete_by_id(user_id)
                                        print("\n\t刪除成功(3秒自動(dòng)返回)")
                                        time.sleep(3)

                    if opt=='back':
                        break;
                    elif opt=='exit':
                        sys.exit(0)

        else:
            print("\n\t登錄失敗(3秒自動(dòng)返回)")
            time.sleep(3)

    elif opt=="2":
        sys.exit(0)

以上就是python mysql項(xiàng)目實(shí)戰(zhàn)的詳細(xì)內(nèi)容,更多關(guān)于python mysql項(xiàng)目實(shí)戰(zhàn)的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • python實(shí)現(xiàn)登錄與注冊系統(tǒng)

    python實(shí)現(xiàn)登錄與注冊系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)登錄與注冊系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-11-11
  • python按時(shí)間排序目錄下的文件實(shí)現(xiàn)方法

    python按時(shí)間排序目錄下的文件實(shí)現(xiàn)方法

    今天小編就為大家分享一篇python按時(shí)間排序目錄下的文件實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-10-10
  • python的debug實(shí)用工具 pdb詳解

    python的debug實(shí)用工具 pdb詳解

    這篇文章主要介紹了python的debug實(shí)用工具 pdb詳解,首先,介紹一下 pdb 調(diào)試,pdb 是 python 的一個(gè)內(nèi)置模塊,用于命令行來調(diào)試 Python 代碼,需要的朋友可以參考下
    2019-07-07
  • keras中的卷積層&池化層的用法

    keras中的卷積層&池化層的用法

    這篇文章主要介紹了keras中的卷積層&池化層的用法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-05-05
  • Python利用contextvars實(shí)現(xiàn)管理上下文變量

    Python利用contextvars實(shí)現(xiàn)管理上下文變量

    Python?在?3.7?的時(shí)候引入了一個(gè)模塊:contextvars,從名字上很容易看出它指的是上下文變量。所以本文就來和大家詳細(xì)講講如何使用contextvars實(shí)現(xiàn)管理上下文變量,需要的可以參考一下
    2022-07-07
  • Python 圖片文字識別的實(shí)現(xiàn)之PaddleOCR

    Python 圖片文字識別的實(shí)現(xiàn)之PaddleOCR

    OCR方向的工程師,之前一定聽說過PaddleOCR這個(gè)項(xiàng)目,其主要推薦的PP-OCR算法更是被國內(nèi)外企業(yè)開發(fā)者廣泛應(yīng)用,短短半年時(shí)間,累計(jì)Star數(shù)量已超過15k,頻頻登上Github Trending和Paperswithcode 日榜月榜第一
    2021-11-11
  • 簡單了解python中的f.b.u.r函數(shù)

    簡單了解python中的f.b.u.r函數(shù)

    這篇文章主要介紹了簡單了解python中的f.b.u.r函數(shù),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • 詳解Python中的進(jìn)程和線程

    詳解Python中的進(jìn)程和線程

    今天帶大家學(xué)習(xí)的是關(guān)于Python的相關(guān)知識,文章圍繞著Python中的進(jìn)程和線程展開,文中有非常詳細(xì)的介紹及代碼示例,需要的朋友可以參考下
    2021-06-06
  • Python堆棧的具體使用

    Python堆棧的具體使用

    本文主要介紹了Python堆棧的具體使用,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-11-11
  • 利用Python如何批量修改數(shù)據(jù)庫執(zhí)行Sql文件

    利用Python如何批量修改數(shù)據(jù)庫執(zhí)行Sql文件

    這篇文章主要給大家介紹了關(guān)于利用Python如何批量修改數(shù)據(jù)庫執(zhí)行Sql文件的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-07-07

最新評論

涪陵区| 建湖县| 宁国市| 腾冲县| 阿拉善右旗| 揭西县| 临泽县| 东台市| 武强县| 沛县| 皮山县| 上栗县| 冀州市| 繁昌县| 舟山市| 尼玛县| 莱州市| 高台县| 津市市| 康保县| 平塘县| 安龙县| 开江县| 百色市| 淳化县| 肥城市| 余干县| 延庆县| 吉安县| 贡嘎县| 河东区| 颍上县| 布拖县| 乐都县| 神农架林区| 井冈山市| 都匀市| 宝山区| 璧山县| 涪陵区| 英山县|