02 初级版web框架
服务器server端python程序(初级版):
1 import socket 2 server=socket.socket() 3 server.bind(("127.0.0.1",8888)) 4 server.listen() 5 conn,client_addr=server.accept() 6 #接收到的请求信息 7 HTTP_Request=conn.recv(1024).decode() 8 print("请求信息:",HTTP_Request) 9 #conn.send(b‘HTTP/1.1200ok\r\ncontent-type:text/html;charset=utf-8;\r\n‘) 10 conn.send("HTTP/1.1 200 ok \r\n\r\n".encode("utf-8")) 11 with open("初级版.html","rb")as f: 12 conn.send(f.read()) 13 conn.close()
客户端浏览器访问:
在浏览器地址栏直接输入地址端口:127.0.0.1:8888
浏览器请求的文件有:
1. ip地址指向的主文件
2. jquery网络分发资源
3. 网络图片资源
4. 标签图标(head标签中的<link rel="icon" href="">)
初级版html:
1 <!DOCTYPE html> 2 3 <html lang="en"> 4 5 <head> 6 7 <Meta charset="UTF-8"> 8 9 <Meta http-equiv="refresh" content=""> 10 11 <Meta name="keywords" content=""> 12 13 <style> 14 15 #d1 { 16 17 background-color: green; 18 19 color: red; 20 21 } 22 23 </style> 24 25 <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script> 26 27 <link rel="icon" href=""> 28 29 <title>初级版</title> 30 31 </head> 32 33 <body> 34 35 <div id="d1"> 36 37 <h1>初级版的页面:本html页面包含了css样式和js代码(其他网络资源)</h1> 38 39 </div> 40 41 <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1557925575771&di=9fc811dca1be2ae5e8084a2c106857bc&imgtype=0&src=http%3A%2F%2Fimg.kutoo8.com%2Fupload%2Fthumb%2F626516%2Fe97c1bbfa346d6c16138f1b1b7bf5d7e_960x540.jpg" 42 43 alt="网络图片" title="网络图片"> 44 45 </body> 46 47 <script> 48 49 alert("基础版的页面") 50 51 </script> 52 53 54 55 </html>