广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Python开发自定义Web框架
  • 877
分享到

Python开发自定义Web框架

python服务器后端 2023-10-04 14:10:43 877人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

文章目录 开发自定义Web框架1.开发Web服务器主体程序2.开发Web框架主体程序3.使用模板来展示响应内容4.开发框架的路由列表功能5.采用装饰器的方式添加路由6.电影列表页面的开发案例

在这里插入图片描述

文章目录

开发自定义WEB框架

接收web服务器的动态资源请求,给web服务器提供处理动态资源请求的服务。根据请求资源路径的后缀名进行判断:

如果请求资源路径的后缀名是.html则是动态资源请求, 让web框架程序进行处理。
否则是静态资源请求,让web服务器程序进行处理。

1.开发Web服务器主体程序

接受客户端Http请求(底层是tcp

# -*- coding: utf-8 -*-# @File  : My_Web_Server.py# @author: Flyme awei # @email : 1071505897@qq.com# @Time  : 2022/7/24 21:28from Socket import *import threading# 开发自己的Web服务器主类class MyHttpWebServer(object):    def __init__(self, port):        # 创建 HTTP服务的 TCP套接字        server_socket = socket(AF_INET, SOCK_STREAM)        # 设置端口号互用,程序退出之后不需要等待,直接释放端口        server_socket.setsockopt(SOL_SOCKET, SO_REUSEADDR, True)        # 绑定 ip和 port        server_socket.bind(('', port))        # listen使套接字变为了被动连接        server_socket.listen(128)        self.server_socket = server_socket    # 处理请求函数    @staticmethod  # 静态方法    def handle_browser_request(new_socket):        # 接受客户端发来的数据        recv_data = new_socket.recv(4096)        # 如果没有数据,那么请求无效,关闭套接字,直接退出        if len(recv_data) == 0:            new_socket.close()            return            # 启动服务器,并接受客户端请求    def start(self):        # 循环并多线程来接收客户端请求        while True:            # accept等待客户端连接            new_socket, ip_port = self.server_socket.accept()            print("客户端ip和端口", ip_port)            # 一个客户端的请求交给一个线程来处理            sub_thread = threading.Thread(target=MyHttpWebServer.handle_browser_request, args=(new_socket, ))            # 设置当前线程为守护线程            sub_thread.setDaemon(True)            sub_thread.start()  # 启动子线程# Web 服务器程序的入口def main():    web_server = MyHttpWebServer(8080)    web_server.start()if __name__ == '__main__':    main()

判断请求是否是静态资源还是动态资源

 # 对接收的字节数据进行转换为字符数据        request_data = recv_data.decode('utf-8')        print("浏览器请求的数据:", request_data)        request_array = request_data.split(' ', maxsplit=2)        # 得到请求路径        request_path = request_array[1]        print("请求的路径是:", request_path)        if request_path == "/":            # 如果请求路径为根目录,自动设置为:/index.html            request_path = "/index.html"        # 判断是否为:.html 结尾        if request_path.endswith(".html"):            "动态资源请求"           pass        else:            "静态资源请求"            pass

如果静态资源怎么处理?
在这里插入图片描述

"静态资源请求"            # 根据请求路径读取/static 目录中的文件数据,相应给客户端            response_body = None  # 响应主体            response_header = None  # 响应头的第一行            response_first_line = None  # 响应头内容            response_type = 'test/html'  # 默认响应类型            try:                # 读取 static目录中相对应的文件数据,rb模式是一种兼容模式,可以打开图片,也可以打开js                with open('static'+request_path, 'rb') as f:                    response_body = f.read()                if request_path.endswith('.jpg'):                    response_type = 'image/webp'                response_first_line = 'HTTP/1.1 200 OK'                response_header = 'Content-Length:' + str(len(response_body)) + '\r\n' + \      'Content-Type: ' + response_type + '; charset=utf-8\r\n' + \      'Date:' + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) + '\r\n' + \      'Server: Flyme awei Server\r\n'            # 浏览器读取的文件可能不存在            except Exception as e:                with open('static/404.html', 'rb') as f:                    response_body = f.read()  # 响应的主体页面内容                # 响应头                response_first_line = 'HTTP/1.1 404 Not Found\r\n'                response_header = 'Content-Length:'+str(len(response_body))+'\r\n' + \      'Content-Type: text/html; charset=utf-8\r\n' + \      'Date:' + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) + '\r\n' + \      'Server: Flyme awei Server\r\n'            # 最后都会执行的代码            finally:                # 组成响应数据发送给(客户端)浏览器                response = (response_first_line + response_header + '\r\n').encode('utf-8') + response_body                new_socket.send(response)                # 关闭套接字                new_socket.close()

在这里插入图片描述
静态资源请求验证:
在这里插入图片描述

如果动态资源又怎么处理

if request_path.endswith(".html"):            "动态资源请求"            # 动态资源的处理交给Web框架来处理,需要把请求参数交给Web框架,可能会有多个参数,采用字典结构            params = {                'request_path': request_path            }            # Web框架处理动态资源请求后,返回一个响应            response = MyFramework.handle_request(params)            new_socket.send(response)            new_socket.close()

关闭Web服务器

new_socket.close()

Web服务器主体框架总代码展示:

# -*- coding: utf-8 -*-# @File  : My_Web_Server.py# @author: Flyme awei # @email : 1071505897@qq.com# @Time  : 2022/7/24 21:28import sysimport timefrom socket import *import threadingimport MyFramework# 开发自己的Web服务器主类class MyHttpWebServer(object):    def __init__(self, port):        # 创建 HTTP服务的 TCP套接字        server_socket = socket(AF_INET, SOCK_STREAM)        # 设置端口号互用,程序退出之后不需要等待,直接释放端口        server_socket.setsockopt(SOL_SOCKET, SO_REUSEADDR, True)        # 绑定 ip和 port        server_socket.bind(('', port))        # listen使套接字变为了被动连接        server_socket.listen(128)        self.server_socket = server_socket    # 处理请求函数    @staticmethod  # 静态方法    def handle_browser_request(new_socket):        # 接受客户端发来的数据        recv_data = new_socket.recv(4096)        # 如果没有数据,那么请求无效,关闭套接字,直接退出        if len(recv_data) == 0:            new_socket.close()            return        # 对接收的字节数据进行转换为字符数据        request_data = recv_data.decode('utf-8')        print("浏览器请求的数据:", request_data)        request_array = request_data.split(' ', maxsplit=2)        # 得到请求路径        request_path = request_array[1]        print("请求的路径是:", request_path)        if request_path == "/":            # 如果请求路径为根目录,自动设置为:/index.html            request_path = "/index.html"        # 判断是否为:.html 结尾        if request_path.endswith(".html"):            "动态资源请求"            # 动态资源的处理交给Web框架来处理,需要把请求参数交给Web框架,可能会有多个参数,采用字典结构            params = {                'request_path': request_path            }            # Web框架处理动态资源请求后,返回一个响应            response = MyFramework.handle_request(params)            new_socket.send(response)            new_socket.close()        else:            "静态资源请求"            # 根据请求路径读取/static 目录中的文件数据,相应给客户端            response_body = None  # 响应主体            response_header = None  # 响应头的第一行            response_first_line = None  # 响应头内容            response_type = 'test/html'  # 默认响应类型            try:                # 读取 static目录中相对应的文件数据,rb模式是一种兼容模式,可以打开图片,也可以打开js                with open('static'+request_path, 'rb') as f:                    response_body = f.read()                if request_path.endswith('.jpg'):                    response_type = 'image/webp'                response_first_line = 'HTTP/1.1 200 OK'                response_header = 'Content-Length:' + str(len(response_body)) + '\r\n' + \      'Content-Type: ' + response_type + '; charset=utf-8\r\n' + \      'Date:' + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) + '\r\n' + \      'Server: Flyme awei Server\r\n'            # 浏览器读取的文件可能不存在            except Exception as e:                with open('static/404.html', 'rb') as f:                    response_body = f.read()  # 响应的主体页面内容                # 响应头                response_first_line = 'HTTP/1.1 404 Not Found\r\n'                response_header = 'Content-Length:'+str(len(response_body))+'\r\n' + \      'Content-Type: text/html; charset=utf-8\r\n' + \      'Date:' + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) + '\r\n' + \      'Server: Flyme awei Server\r\n'            # 最后都会执行的代码            finally:                # 组成响应数据发送给(客户端)浏览器                response = (response_first_line + response_header + '\r\n').encode('utf-8') + response_body                new_socket.send(response)                # 关闭套接字                new_socket.close()    # 启动服务器,并接受客户端请求    def start(self):        # 循环并多线程来接收客户端请求        while True:            # accept等待客户端连接            new_socket, ip_port = self.server_socket.accept()            print("客户端ip和端口", ip_port)            # 一个客户端的请求交给一个线程来处理            sub_thread = threading.Thread(target=MyHttpWebServer.handle_browser_request, args=(new_socket, ))            # 设置当前线程为守护线程            sub_thread.setDaemon(True)            sub_thread.start()  # 启动子线程# Web 服务器程序的入口def main():    web_server = MyHttpWebServer(8080)    web_server.start()if __name__ == '__main__':    main()

2.开发Web框架主体程序

根据请求路径,动态的响应对应的数据

# -*- coding: utf-8 -*-# @File  : MyFramework.py# @author: Flyme awei # @email : 1071505897@qq.com# @Time  : 2022/7/25 14:05import time# 自定义Web框架# 处理动态资源请求的函数def handle_request(parm):    request_path = parm['request_path']    if request_path == '/index.html':  # 当前请求路径有与之对应的动态响应,当前框架只开发了 index.html的功能        response = index()        return response    else:        # 没有动态资源的数据,返回404页面        return page_not_found()# 当前 index函数,专门处理index.html的请求def index():    # 需求,在页面中动态显示当前系统时间    data = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())    response_body = data    response_first_line = 'HTTP/1.1 200 OK\r\n'    response_header = 'Content-Length:' + str(len(response_body)) + '\r\n' + \                      'Content-Type: text/html; charset=utf-8\r\n' + \                      'Date:' + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) + '\r\n' + \                      'Server: Flyme awei Server\r\n'    response = (response_first_line + response_header + '\r\n' + response_body).encode('utf-8')    return responsedef page_not_found():    with open('static/404.html', 'rb') as f:        response_body = f.read()  # 响应的主体页面内容    # 响应头    response_first_line = 'HTTP/1.1 404 Not Found\r\n'    response_header = 'Content-Length:' + str(len(response_body)) + '\r\n' + \                      'Content-Type: text/html; charset=utf-8\r\n' + \                      'Date:' + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) + '\r\n' + \                      'Server: Flyme awei Server\r\n'    response = (response_first_line + response_header + '\r\n').encode('utf-8') + response_body    return response    

如果请求路径,没有对应的响应数据也需要返回404页面
在这里插入图片描述

3.使用模板来展示响应内容

自己设计一个模板 index.html ,中有一些地方采用动态的数据来替代

<html lang="zh-CN"><head>    <meta charset="utf-8">    <meta http-equiv="X-UA-Compatible" content="IE=edge">    <meta name="viewport" content="width=device-width, initial-scale=1">    <title>首页 - 电影列表title>    <link href="/CSS/bootstrap.min.css" rel="stylesheet">    <script src="/js/Jquery-1.12.4.min.js">script>    <script src="/js/bootstrap.min.js">script>head><body><div class="navbar navbar-inverse navbar-static-top ">        <div class="container">        <div class="navbar-header">                <button class="navbar-toggle" data-toggle="collapse" data-target="#mymenu">                        <span class="icon-bar">span>                        <span class="icon-bar">span>                        <span class="icon-bar">span>                 button>                 <a href="#" class="navbar-brand">电影列表a>        div>        <div class="collapse navbar-collapse" id="mymenu">                <ul class="nav navbar-nav">                        <li class="active"><a href="">电影信息a>li>                        <li><a href="">个人中心a>li>                ul>        div>        div>div><div class="container">    <div class="container-fluid">        <table class="table table-hover">            <tr>                    <th>序号th>                    <th>名称th>                    <th>导演th>                    <th>上映时间th>                    <th>票房th>                    <th>电影时长th>                    <th>类型th>                    <th>备注th>                    <th>删除电影th>            tr>            {%datas%}        table>    div>div>body>html>

怎么替代,替代什么数据

 response_body = response_body.replace('{%datas%}', data)

在这里插入图片描述

4.开发框架的路由列表功能

以后开发新的动作资源的功能,只需要:
a、增加一个条件判断分支
b、增加一个专门处理的函数

路由: 就是请求的URL路径和处理函数直接的映射。

路由表

请求路径处理函数
/index.htmlindex函数
/user_info.htmluser_info函数
# 定义路由表route_list = {    ('/index.html', index),    ('/user_info.html', user_info)}for path, func in route_list:    if request_path == path:        return func()    else:        # 没有动态资源的数据,返回404页面        return page_not_found()          

注意:用户的动态资源请求,通过遍历路由表找到对应的处理函数来完成的。

5.采用装饰器的方式添加路由

采用带参数的装饰器

# -*- coding: utf-8 -*-# @File  : My_Web_Server.py# @author: Flyme awei # @email : 1071505897@qq.com# @Time  : 2022/7/24 21:28# 定义路由表route_list = []# route_list = {# ('/index.html', index),# ('/user_info.html', user_info)# }# 定义一个带参数的装饰器def route(request_path):  # 参数就是URL请求    def add_route(func):        # 添加路由表        route_list.append((request_path, func))        @wraps(func)        def invoke(*args, **kwargs):            # 调用指定的处理函数,并返回结果            return func()        return invoke    return add_route# 处理动态资源请求的函数def handle_request(parm):    request_path = parm['request_path']    # if request_path == '/index.html':  # 当前请求路径有与之对应的动态响应,当前框架只开发了 index.html的功能    #     response = index()    #     return response    # elif request_path == '/user_info.html':  # 个人中心的功能    #     return user_info()    # else:    #     # 没有动态资源的数据,返回404页面    #     return page_not_found()    for path, func in route_list:        if request_path == path:            return func()        else:            # 没有动态资源的数据,返回404页面            return page_not_found()

在任何一个处理函数的基础上增加一个添加路由的功能

@route('/user_info.html')

小结:使用带参数的装饰器,可以把我们的路由自动的,添加到路由表中。

6.电影列表页面的开发案例

在这里插入图片描述

查询数据
my_web.py

# -*- coding: utf-8 -*-# @File  : My_Web_Server.py# @author: Flyme awei # @email : 1071505897@qq.com# @Time  : 2022/7/24 21:28import socketimport sysimport threadingimport timeimport MyFramework# 开发自己的Web服务器主类class MyHttpWebServer(object):    def __init__(self, port):        # 创建HTTP服务器的套接字        server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)        # 设置端口号复用,程序退出之后不需要等待几分钟,直接释放端口        server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)        server_socket.bind(('', port))        server_socket.listen(128)        self.server_socket = server_socket    # 处理浏览器请求的函数    @staticmethod    def handle_browser_request(new_socket):        # 接受客户端发送过来的数据        recv_data = new_socket.recv(4096)        # 如果没有收到数据,那么请求无效,关闭套接字,直接退出        if len(recv_data) == 0:            new_socket.close()            return        # 对接受的字节数据,转换成字符        request_data = recv_data.decode('utf-8')        print("浏览器请求的数据:", request_data)        request_array = request_data.split(' ', maxsplit=2)        # 得到请求路径        request_path = request_array[1]        print('请求路径是:', request_path)        if request_path == '/':  # 如果请求路径为跟目录,自动设置为/index.html            request_path = '/index.html'        # 根据请求路径来判断是否是动态资源还是静态资源        if request_path.endswith('.html'):            '''动态资源的请求'''            # 动态资源的处理交给Web框架来处理,需要把请求参数传给Web框架,可能会有多个参数,所有采用字典机构            params = {                'request_path': request_path,            }            # Web框架处理动态资源请求之后,返回一个响应            response = MyFramework.handle_request(params)            new_socket.send(response)            new_socket.close()        else:            '''静态资源的请求'''            response_body = None  # 响应主体            response_header = None  # 响应头            response_first_line = None  # 响应头的第一行            # 其实就是:根据请求路径读取/static目录中静态的文件数据,响应给客户端            try:                # 读取static目录中对应的文件数据,rb模式:是一种兼容模式,可以打开图片,也可以打开js                with open('static' + request_path, 'rb') as f:                    response_body = f.read()                if request_path.endswith('.jpg'):                    response_type = 'image/webp'                response_first_line = 'HTTP/1.1 200 OK'                response_header = 'Server: Laoxiao_Server\r\n'            except Exception as e:  # 浏览器想读取的文件可能不存在                with open('static/404.html', 'rb') as f:                    response_body = f.read()  # 响应的主体页面内容(字节)                # 响应头 (字符数据)                response_first_line = 'HTTP/1.1 404 Not Found\r\n'                response_header = 'Server: Laoxiao_Server\r\n'            finally:                # 组成响应数据,发送给客户端(浏览器)                response = (response_first_line + response_header + '\r\n').encode('utf-8') + response_body                new_socket.send(response)                new_socket.close()  # 关闭套接字    # 启动服务器,并且接受客户端的请求    def start(self):        # 循环并且多线程来接受客户端的请求        while True:            new_socket, ip_port = self.server_socket.accept()            print("客户端的ip和端口", ip_port)            # 一个客户端请求交给一个线程来处理            sub_thread = threading.Thread(target=MyHttpWebServer.handle_browser_request, args=(new_socket,))            sub_thread.setDaemon(True)  # 设置当前线程为守护线程            sub_thread.start()  # 子线程要启动# web服务器程序的入口def main():    web_server = MyHttpWebServer(8080)    web_server.start()if __name__ == '__main__':    main()

MyFramework.py

# -*- coding: utf-8 -*-# @File  : My_Web_Server.py# @author: Flyme awei # @email : 1071505897@qq.com# @Time  : 2022/7/24 21:28import timefrom functools import wrapsimport pyMysql# 定义路由表route_list = []# route_list = {#     # ('/index.html',index),#     # ('/userinfo.html',user_info)# }# 定义一个带参数装饰器def route(request_path):  # 参数就是URL请求    def add_route(func):        # 添加路由到路由表        route_list.append((request_path, func))        @wraps(func)        def invoke(*arg, **kwargs):            # 调用我们指定的处理函数,并且返回结果            return func()        return invoke    return add_route# 处理动态资源请求的函数def handle_request(params):    request_path = params['request_path']    for path, func in route_list:        if request_path == path:            return func()    else:        # 没有动态资源的数据,返回404页面        return page_not_found()    # if request_path =='/index.html': # 当前的请求路径有与之对应的动态响应,当前框架,我只开发了index.html的功能    #     response = index()    #     return response    #    # elif request_path =='/userinfo.html': # 个人中心的功能,user_info.html    #     return user_info()    # else:    #     # 没有动态资源的数据,返回404页面    #     return page_not_found()# 当前user_info函数,专门处理userinfo.html的动态请求@route('/userinfo.html')def user_info():    # 需求:在页面中动态显示当前系统时间    date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())    # response_body =data    with open('template/user_info.html', 'r', encoding='utf-8') as f:        response_body = f.read()    response_body = response_body.replace('{%datas%}', date)    response_first_line = 'HTTP/1.1 200 OK\r\n'    response_header = 'Server: Laoxiao_Server\r\n'    response = (response_first_line + response_header + '\r\n' + response_body).encode('utf-8')    return response# 当前index函数,专门处理index.html的请求@route('/index.html')def index():    # 需求:从数据库中取得所有的电影数据,并且动态展示    # date = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())    # response_body =data    # 1、从mysql中查询数据    conn = pymysql.connect(host='localhost', port=3306, user='root', passWord='******', database='test', charset='utf8')    cursor = conn.cursor()    cursor.execute('select * from t_movies')    result = cursor.fetchall()    # print(result)    datas = ""    for row in result:        datas += '''                %s                %s                %s                %s                %s 亿人民币                %s                %s                %s                                                  ''' % row    print(datas)    # 把查询的数据,转换成动态内容    with open('template/index.html', 'r', encoding='utf-8') as f:        response_body = f.read()    response_body = response_body.replace('{%datas%}', datas)    response_first_line = 'HTTP/1.1 200 OK\r\n'    response_header = 'Server: Laoxiao_Server\r\n'    response = (response_first_line + response_header + '\r\n' + response_body).encode('utf-8')    return response# 处理没有找到对应的动态资源def page_not_found():    with open('static/404.html', 'rb') as f:        response_body = f.read()  # 响应的主体页面内容(字节)    # 响应头 (字符数据)    response_first_line = 'HTTP/1.1 404 Not Found\r\n'    response_header = 'Server: Laoxiao_Server\r\n'    response = (response_first_line + response_header + '\r\n').encode('utf-8') + response_body    return response

根据查询的数据得到动态的内容
在这里插入图片描述

来源地址:https://blog.csdn.net/m0_68744965/article/details/125964322

--结束END--

本文标题: Python开发自定义Web框架

本文链接: https://www.lsjlt.com/news/423403.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Python开发自定义Web框架
    文章目录 开发自定义Web框架1.开发Web服务器主体程序2.开发Web框架主体程序3.使用模板来展示响应内容4.开发框架的路由列表功能5.采用装饰器的方式添加路由6.电影列表页面的开发案例...
    99+
    2023-10-04
    python 服务器 后端
  • 怎么使用Python开发自定义Web框架
    开发自定义Web框架接收web服务器的动态资源请求,给web服务器提供处理动态资源请求的服务。根据请求资源路径的后缀名进行判断:如果请求资源路径的后缀名是.html则是动态资源请求, 让web框架程序进行处理。否则是静态资源请求,让web服...
    99+
    2023-05-17
    Python web
  • Python开发自定义Web框架的示例详解
    目录开发自定义Web框架1.开发Web服务器主体程序2.开发Web框架主体程序3.使用模板来展示响应内容4.开发框架的路由列表功能5.采用装饰器的方式添加路由6.电影列表页面的开发案...
    99+
    2022-11-11
  • 自定义用于Web开发的开源PHP框架Codeigniter是怎么样的
    自定义用于Web开发的开源PHP框架Codeigniter是怎么样的,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。Codeigniter 是一个 PHP 框架,可以使公司进行开...
    99+
    2023-06-16
  • 200行自定义python异步非阻塞Web框架
    Python的Web框架中Tornado以异步非阻塞而闻名。本篇将使用200行代码完成一个微型异步非阻塞Web框架:Snow。 一、源码 本文基于非阻塞的Socket以及IO多路复用从而实现异步非阻塞的We...
    99+
    2022-06-04
    自定义 框架 Web
  • Python web开发框架Pyramid怎么用
    要使用Python web开发框架Pyramid,你需要按照以下步骤进行操作: 安装Pyramid:使用pip命令安装Pyram...
    99+
    2023-10-23
    Python Pyramid
  • python中web开发框架有哪些
    python中的web开发框架有Django、web.py、Bottle、Flask常见的几种DjangoDjango是一个开放源代码的Web应用框架,由Python编写,其采用了MTV框架模式,具有易维护、高度可定制和可扩展的特点。web...
    99+
    2022-10-19
  • 37 个 Python Web 开发框架总结
    Q:Web 框架到底是什么?A:Web 框架主要用于网站开发。开发者在基于 Web 框架实现自己的业务逻辑。Web 框架实现了很多功能,为实现业务逻辑提供了一套通用方法。Q:Web 框架有什么作用?A:使用 Web 框架,很多的业务逻辑外的...
    99+
    2023-05-14
    Python Web 开发框
  • Java Web开发中怎么自定义Session
    今天小编给大家分享一下Java Web开发中怎么自定义Session的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下...
    99+
    2022-10-19
  • 我的第一个python web开发框架(
      前面ORM模块我们已经完成了开发,接下来要做的就是对项目代码进行重构了。因为对底层数据库操作模块(db_helper.py)进行了改造,之前项目的接口代码全都跑不起来了。   在写ORM模块时,我们已经对产品接口的分页查询、新增、修改...
    99+
    2023-01-30
    第一个 框架 python
  • Python使用Web框架Flask开发项目
    目录一、简介二、安装三、从 Hello World 开始3.1 Hello World3.2 修改Flask的配置3.3 调试模式3.4 绑定IP和端口3.5 本节源码四、获取 UR...
    99+
    2022-11-11
  • Python Web开发用Flask还Django框架好
    本篇内容主要讲解“Python Web开发用Flask还Django框架好”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Python Web开发用Flask还Django框架好”吧!是否有考虑过...
    99+
    2023-06-02
  • Web开发最佳的Python框架有哪些
    这篇文章将为大家详细讲解有关Web开发最佳的Python框架有哪些,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。Python 时目前最流行和代码最高效的编程语言之一。Python框架能帮助你...
    99+
    2023-06-19
  • Python中的Web开发框架怎么使用
    这篇文章主要介绍了Python中的Web开发框架怎么使用的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Python中的Web开发框架怎么使用文章都会有所收获,下面我们一起来看看吧。在开始之前,我们先要安装好需要...
    99+
    2023-07-06
  • Android WebView开发之自定义WebView工具框
    附GitHub源码:WebViewExplore 先看图: 在WebView页面长按时会弹出一个复制框,但如果里面的item不是我们想要的或者想自定义,那么可以通过覆盖WebVie...
    99+
    2022-11-12
  • python Django框架实现自定义表单提交
    除了使用Django内置表单,有时往往我们需要自定义表单。对于自定义表单Post方式提交往往会带来由CSRF(跨站请求伪造)产生的错误"CSRF verification failed. Request a...
    99+
    2022-06-04
    自定义 表单 框架
  • web开发框架之Django基础
      在脚本中如何进行Django的运行 if __name__ == '__main__': import os import django # 注意路径(当前所在的位置,要加载Django的配置文件) ...
    99+
    2023-01-30
    框架 基础 web
  • web前端框架开发是啥
    Web前端框架,是一种助力Web前端开发的工具,它们在JavaScript编程语言基础之上,往往提供了一些抽象层和约束,以便开发人员能够更加迅速地编写出高质量的Web前端应用。Web前端框架有多种,比如目前最为流行的React、Angula...
    99+
    2023-05-20
  • web开发框架Flask学习一
    flask框架 用Python做Web开发的三大框架特点 Django 主要特点是大而全,集成了很多的组件,例如:Admin Form Model等,不管你用不用的到,他都会为 ...
    99+
    2023-01-30
    框架 web Flask
  • web开发框架Flask学习二
    jinja2模板规范 在当前项目中创建一个文件为templates的文件夹,将其设置为模板文件夹,新建的html为模板页面, 在视图函数中使用render_template(".html的文件", my_...
    99+
    2023-01-30
    框架 web Flask
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作