• Python_自定义模块


    自定义模块例子(web简单框架):

      专门处理逻辑的包:处理各种访问需求

      数据库的交互:面临各种的查询,删改 ,dba,

      配置文件(全局配置文件):列存储数据的地方,HTML代码存储地方

    实现:

    代码:

    from 后端.处理逻辑 import handle处理
    handle处理.home()
    启动程序

    代码:

    from 后端.数据库交互.程序接口 import select
    
    def home():
        print('欢迎来到home页面')
    
        m = select('user', 'come on')
        print('程序接口下的东西:', m)
    
    def movie():
        print('欢迎来到movie页面')
    
    
    def tv():
        print('欢迎来到tv页面')
    handle处理

    代码:

    from 全局配置文件 import settings
    
    # db_auth 最好写在后端作为单独验证的文件
    def db_auth(configs):       # configs 配置
        if configs.DATABASE['user'] == 'root' and configs.DATABASE['password'] == '123':
            print('后端数据库验证成功')
            return True
        else:
            print('验证失败')
    
    
    
    def select(table,column):
    
        if db_auth(settings):       # db_auth 数据库交互认证,验证
            if table == 'user':
                user_info = {
                    '001': ['Presly', 23, '运维'],
                    '002': ['Vera', 19, '自动化开发']
                }
                return user_info
    程序接口

    代码:

    # 数据库配置信息
    DATABASE = {
        'engine': 'mysql',          # engine:数据库引擎
        'host': 'localhost',        # 连接host
        'port': 3306,               # 连接 port
        'user': 'root',
        'password': '123'
    }
    settings

    全局:

    全局分析:

  • 相关阅读:
    CF949C Data Center Maintenance 题解
    P1438 无聊的数列 题解
    CF620E New Year Tree 题解
    结构体优先队列的定义
    CF464E The Classic Problem 题解
    CF427C Checkposts
    CF161D Distance in Tree 题解
    P4375 [USACO18OPEN]Out of Sorts G 题解
    SCI, SCIE, 和ESCI的区别
    Matlab画图中图的方法
  • 原文地址:https://www.cnblogs.com/Vera-y/p/9642222.html
Copyright © 2020-2023  润新知