歡迎光臨
每天分享高質量文章

Django:瀏覽器訪問服務器的過程。

用戶通過瀏覽器瀏覽網站的過程:

  用戶瀏覽器(socket客戶端)

      客戶端往服務端發訊息
    客戶端接收訊息
    關閉

  網站服務器(socket服務端)

   啟動,監聽
      等待客戶端連接
    服務端收訊息
    服務端回訊息
    關閉(一般都不會關閉)

下麵,我們先寫一個服務端程式,來模擬瀏覽器服務器訪問過程。

你會發現,運行程式之後並且用瀏覽器訪問 127.0.0.1:8001 ,程式會報錯,瀏覽器顯示“該網頁無法正常運作”,如下圖

為什麼呢?這時候就要引出 HTTP 協議了。

HTTP協議

HTTP是一個客戶端終端(用戶)和服務器端(網站)請求和應答的標準(TCP)。

HTTP請求/響應步驟:

1. 客戶端連接到Web服務器
一個HTTP客戶端,通常是瀏覽器,與Web服務器的HTTP端口(預設為80)建立一個TCP套接字連接。

2. 發送HTTP請求
通過TCP套接字,客戶端向Web服務器發送一個文本的請求報文,一個請求報文由請求行、請求頭部、空行和請求資料4部分組成。

3. 服務器接受請求並傳回HTTP響應
Web服務器解析請求,定位請求資源。服務器將資源複本寫到TCP套接字,由客戶端讀取。一個響應由狀態行、響應頭部、空行和響應資料4部分組成。

4. 釋放連接TCP連接
若connection 樣式為close,則服務器主動關閉TCP連接,客戶端被動關閉連接,釋放TCP連接;若connection 樣式為keepalive,則該連接會保持一段時間,在該時間內可以繼續接收請求;

5. 客戶端瀏覽器解析HTML內容
客戶端瀏覽器首先解析狀態行,查看表明請求是否成功的狀態代碼。然後解析每一個響應頭,響應頭告知以下為若干位元組的HTML文件和文件的字符集。客戶端瀏覽器讀取響應資料HTML,根據HTML的語法對其進行格式化,併在瀏覽器視窗中顯示。

瀏覽器和服務端通信都要遵循一個HTTP協議(訊息的格式要求)

關於HTTP協議:

1. 瀏覽器往服務端發的叫 請求(request)
 請求的訊息格式:

請求方法 路徑 HTTP/1.1\r\n
k1:v1\r\n
k2:v2\r\n
\r\n
請求資料

2. 服務端往瀏覽器發的叫 響應(response)
 響應的訊息格式:

HTTP/1.1 狀態碼 狀態描述符\r\n
k1:v1\r\n
k2:v2\r\n
\r\n
響應正文

 

HTTP請求報文格式:

HTTP響應報文格式:

再回到我們剛纔的程式,程式報錯的原因是接收到了瀏覽器的訪問報文請求,但是我們的服務器程式在響應的時候並沒有按照HTTP響應格式(一個響應由狀態行、響應頭部、空行和響應資料4部分組成)進行回應,所以瀏覽器在處理服務器的響應的時候就會出錯。

因此,我們要在發送給瀏覽器的響應中按照HTTP響應格式加上 狀態行、響應頭部、空行和響應資料 這四部分。

這時候,在瀏覽器上面就可以看到正確的頁面了,並且可以調出Chrome的開發者工具查看到我們傳過來的HTTP響應格式。

 

 根據不同的路徑傳回不同的內容

細心的你可能會發現,現在無論我們輸出什麼樣的路徑,只要保持 IP 和端口號不變,瀏覽器頁面顯示的都是同樣的內容,這不太符合我們日常的使用場景。

如果我想根據不同的路徑傳回不同的內容,應該怎麼辦呢?

這時候就需要我們把服務器收到的請求報文進行解析,讀取到其中的訪問路徑。

觀察收到的HTTP請求,會發現,它們的請求行、請求頭部、請求資料是以 \r\n 進行分隔的,所以我們可以根據 \r\n 對收到的請求進行分隔,取出我們想要的訪問路徑。

  1. """

  2. 完善的web服務端示例

  3. 根據不同的路徑傳回不同的內容

  4. """

  5. import socket

  6. # 生成socket實體物件

  7. sk = socket.socket()

  8. # 系結IP和端口

  9. sk.bind(("127.0.0.1", 8001))

  10. # 監聽

  11. sk.listen()

  12. # 寫一個死迴圈,一直等待客戶端來連接

  13. while 1:

  14.    # 獲取與客戶端的連接

  15.    conn, _ = sk.accept()

  16.    # 接收客戶端發來訊息

  17.    data = conn.recv(8096)

  18.    # 把收到的資料轉成字串型別

  19.    data_str = str(data, encoding="utf-8")  # bytes("str", enconding="utf-8")

  20.    # print(data_str)

  21.    # 用\r\n去切割上面的字串

  22.    l1 = data_str.split("\r\n")

  23.    # l1[0]獲得請求行,按照空格切割上面的字串

  24.    l2 = l1[0].split()

  25.    # 請求行格式為:請求方法 URL 協議版本,因此 URL 是 l2[1]

  26.    url = l2[1]

  27.    # 給客戶端回覆訊息

  28.    conn.send(b'http/1.1 200 OK\r\ncontent-type:text/html; charset=utf-8\r\n\r\n')

  29.    # 想讓瀏覽器在頁面上顯示出來的內容都是響應正文

  30.    # 根據不同的url傳回不同的內容

  31.    if url == "/yimi/":

  32.        response = b'

    hello yimi!

    '

  33.    elif url == "/xiaohei/":

  34.        response = b'

    hello xiaohei!

    '

  35.    else:

  36.        response = b'

    404! not found!

    '

  37.    conn.send(response)

  38.    # 關閉

  39.    conn.close()

  40.    sk.close()

這時候,我們訪問不同的路徑,例如 http://127.0.0.1:8001/yimi/   http://127.0.0.1:8001/xiaohei/ 會在瀏覽器上顯示不一樣的內容

可以看到,我們現在的程式邏輯不是很清晰,我們可以改一下,url 用一個串列存起來,url 對應的響應分別寫成一個個函式,通過函式呼叫進行 url 訪問,你會發現,這跟某個框架的處理方式很像很像(偷笑罒ω罒~~~)

  1. """

  2. 完善的web服務端示例

  3. 函式版根據不同的路徑傳回不同的內容

  4. 進階函式版 不寫if判斷了,用url名字去找對應的函式名

  5. """

  6. import socket

  7. # 生成socket實體物件

  8. sk = socket.socket()

  9. # 系結IP和端口

  10. sk.bind(("127.0.0.1", 8001))

  11. # 監聽

  12. sk.listen()

  13. # 定義一個處理/yimi/的函式

  14. def yimi(url):

  15.    ret = '

    hello {}

    '.format(url)

  16.    # 因為HTTP傳的是位元組,所以要把上面的字串轉成位元組

  17.    return bytes(ret, encoding="utf-8")

  18. # 定義一個處理/xiaohei/的函式

  19. def xiaohei(url):

  20.    ret = '

    hello {}

    '.format(url)

  21.    return bytes(ret, encoding="utf-8")

  22. # 定義一個專門用來處理404的函式

  23. def f404(url):

  24.    ret = "

    你訪問的這個{} 找不到

    ".format(url)

  25.    return bytes(ret, encoding="utf-8")

  26. url_func = [

  27.    ("/yimi/", yimi),

  28.    ("/xiaohei/", xiaohei),

  29. ]

  30. # 寫一個死迴圈,一直等待客戶端來連我

  31. while 1:

  32.    # 獲取與客戶端的連接

  33.    conn, _ = sk.accept()

  34.    # 接收客戶端發來訊息

  35.    data = conn.recv(8096)

  36.    # 把收到的資料轉成字串型別

  37.    data_str = str(data, encoding="utf-8")  # bytes("str", enconding="utf-8")

  38.    # print(data_str)

  39.    # 用\r\n去切割上面的字串

  40.    l1 = data_str.split("\r\n")

  41.    # print(l1[0])

  42.    # 按照空格切割上面的字串

  43.    l2 = l1[0].split()

  44.    url = l2[1]

  45.    # 給客戶端回覆訊息

  46.    conn.send(b'http/1.1 200 OK\r\ncontent-type:text/html; charset=utf-8\r\n\r\n')

  47.    # 想讓瀏覽器在頁面上顯示出來的內容都是響應正文

  48.    # 根據不同的url傳回不同的內容

  49.    # 去url_func裡面找對應關係

  50.    for i in url_func:

  51.        if i[0] == url:

  52.            func = i[1]

  53.            break

  54.    # 找不到對應關係就預設執行f404函式

  55.    else:

  56.        func = f404

  57.    # 拿到函式的執行結果

  58.    response = func(url)

  59.    # 將函式傳回的結果發送給瀏覽器

  60.    conn.send(response)

  61.    # 關閉連接

  62.    conn.close()

 傳回具體的 HTML 頁面

現在,你可能會在想,目前我們想要傳回的內容是通過函式進行傳回的,傳回的都是一些簡單地位元組,如果我想要傳回一個已經寫好的精美的 HTML 頁面應該怎麼辦呢?

我們可以把寫好的 HTML 頁面以二進制的形式讀取進來,傳回給瀏覽器,瀏覽器再進行解析,這就可以啦!

  1. """

  2. 完善的web服務端示例

  3. 函式版根據不同的路徑傳回不同的內容

  4. 進階函式版 不寫if判斷了,用url名字去找對應的函式名

  5. 傳回html頁面

  6. """

  7. import socket

  8. # 生成socket實體物件

  9. sk = socket.socket()

  10. # 系結IP和端口

  11. sk.bind(("127.0.0.1", 8001))

  12. # 監聽

  13. sk.listen()

  14. # 定義一個處理/yimi/的函式

  15. def yimi(url):

  16.    # 以二進制的形式讀取

  17.    with open("yimi.html", "rb") as f:

  18.       ret = f.read()

  19.    return ret

  20. # 定義一個處理/xiaohei/的函式

  21. def xiaohei(url):

  22.    with open("xiaohei.html", "rb") as f:

  23.       ret = f.read()

  24.    return ret

  25. # 定義一個專門用來處理404的函式

  26. def f404(url):

  27.    ret = "

    你訪問的這個{} 找不到

    ".format(url)

  28.    return bytes(ret, encoding="utf-8")

  29. # 用戶訪問的路徑和後端要執行的函式的對應關係

  30. url_func = [

  31.    ("/yimi/", yimi),

  32.    ("/xiaohei/", xiaohei),

  33. ]

  34. # 寫一個死迴圈,一直等待客戶端來連我

  35. while 1:

  36.    # 獲取與客戶端的連接

  37.    conn, _ = sk.accept()

  38.    # 接收客戶端發來訊息

  39.    data = conn.recv(8096)

  40.    # 把收到的資料轉成字串型別

  41.    data_str = str(data, encoding="utf-8")  # bytes("str", enconding="utf-8")

  42.    # print(data_str)

  43.    # 用\r\n去切割上面的字串

  44.    l1 = data_str.split("\r\n")

  45.    # print(l1[0])

  46.    # 按照空格切割上面的字串

  47.    l2 = l1[0].split()

  48.    url = l2[1]

  49.    # 給客戶端回覆訊息

  50.    conn.send(b'http/1.1 200 OK\r\ncontent-type:text/html; charset=utf-8\r\n\r\n')

  51.    # 想讓瀏覽器在頁面上顯示出來的內容都是響應正文

  52.    # 根據不同的url傳回不同的內容

  53.    # 去url_func裡面找對應關係

  54.    for i in url_func:

  55.        if i[0] == url:

  56.            func = i[1]

  57.            break

  58.    # 找不到對應關係就預設執行f404函式

  59.    else:

  60.        func = f404

  61.    # 拿到函式的執行結果

  62.    response = func(url)

  63.    # 將函式傳回的結果發送給瀏覽器

  64.    conn.send(response)

  65.    # 關閉連接

  66.    conn.close()

 傳回動態 HTML 頁面

這時候,你可能又會納悶,現在傳回的都是些靜態的、固定的 HTML 頁面,如果我想傳回一個動態的 HTML 頁面,應該怎麼辦?

動態的網頁,本質上都是字串的替換,字串替換髮生服務端,替換完再傳回給瀏覽器。

這裡,我們通過傳回一個當前時間,來模擬動態 HTML 頁面的傳回過程。

  1. """

  2. 完善的web服務端示例

  3. 函式版根據不同的路徑傳回不同的內容

  4. 進階函式版 不寫if判斷了,用url名字去找對應的函式名

  5. 傳回html頁面

  6. 傳回動態的html頁面

  7. """

  8. import socket

  9. import time

  10. # 生成socket實體物件

  11. sk = socket.socket()

  12. # 系結IP和端口

  13. sk.bind(("127.0.0.1", 8001))

  14. # 監聽

  15. sk.listen()

  16. # 定義一個處理/yimi/的函式

  17. def yimi(url):

  18.    with open("yimi.html", "r", encoding="utf-8") as f:

  19.       ret = f.read()

  20.    # 得到替換後的字串

  21.    ret2 = ret.replace("@@[email protected]@", str(time.ctime()))

  22.    return bytes(ret2, encoding="utf-8")

  23. # 定義一個處理/xiaohei/的函式

  24. def xiaohei(url):

  25.    with open("xiaohei.html", "rb") as f:

  26.       ret = f.read()

  27.    return ret

  28. # 定義一個專門用來處理404的函式

  29. def f404(url):

  30.    ret = "你訪問的這個{} 找不到".format(url)

  31.    return bytes(ret, encoding="utf-8")

  32. url_func = [

  33.    ("/yimi/", yimi),

  34.    ("/xiaohei/", xiaohei),

  35. ]

  36. # 寫一個死迴圈,一直等待客戶端來連我

  37. while 1:

  38.    # 獲取與客戶端的連接

  39.    conn, _ = sk.accept()

  40.    # 接收客戶端發來訊息

  41.    data = conn.recv(8096)

  42.    # 把收到的資料轉成字串型別

  43.    data_str = str(data, encoding="utf-8")  # bytes("str", enconding="utf-8")

  44.    # print(data_str)

  45.    # 用\r\n去切割上面的字串

  46.    l1 = data_str.split("\r\n")

  47.    # print(l1[0])

  48.    # 按照空格切割上面的字串

  49.    l2 = l1[0].split()

  50.    url = l2[1]

  51.    # 給客戶端回覆訊息

  52.    conn.send(b'http/1.1 200 OK\r\ncontent-type:text/html; charset=utf-8\r\n\r\n')

  53.    # 想讓瀏覽器在頁面上顯示出來的內容都是響應正文

  54.    # 根據不同的url傳回不同的內容

  55.    # 去url_func裡面找對應關係

  56.    for i in url_func:

  57.        if i[0] == url:

  58.            func = i[1]

  59.            break

  60.    # 找不到對應關係就預設執行f404函式

  61.    else:

  62.        func = f404

  63.    # 拿到函式的執行結果

  64.    response = func(url)

  65.    # 將函式傳回的結果發送給瀏覽器

  66.    conn.send(response)

  67.    # 關閉連接

  68.    conn.close()


  69. lang="en">

  70.     charset="UTF-8">

  71.    </span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">yimi</span><span class="tag" style="box-sizing: border-box;color: rgb(242, 44, 64);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"/></code></span></span></p> </li> </ol> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border: 0px;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="tag" style="box-sizing: border-box;color: rgb(242, 44, 64);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"/></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border: 0px;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="tag" style="box-sizing: border-box;color: rgb(242, 44, 64);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"/></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border: 0px;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    </span><span class="tag" style="box-sizing: border-box;color: rgb(242, 44, 64);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"></p> <h1/></span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">Hello yimi</span><span class="tag" style="box-sizing: border-box;color: rgb(242, 44, 64);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"/></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border: 0px;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    </span><span class="tag" style="box-sizing: border-box;color: rgb(242, 44, 64);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"></p> <h3><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> </span><span class="atn" style="box-sizing: border-box;color: rgb(223, 83, 32);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">style</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="atv" style="box-sizing: border-box;color: rgb(61, 151, 184);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">background</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">-</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">color</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">:</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> pink</span><span class="atv" style="box-sizing: border-box;color: rgb(61, 151, 184);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"</span><span class="tag" style="box-sizing: border-box;color: rgb(242, 44, 64);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">></span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">這是yimi的小站!</span><span class="tag" style="box-sizing: border-box;color: rgb(242, 44, 64);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"/></h3> <p></span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border: 0px;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    </span><span class="tag" style="box-sizing: border-box;color: rgb(242, 44, 64);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"></p> <h4/></span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">@@xx@@</span><span class="tag" style="box-sizing: border-box;color: rgb(242, 44, 64);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"/></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border: 0px;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="tag" style="box-sizing: border-box;color: rgb(242, 44, 64);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"/></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border: 0px;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="tag" style="box-sizing: border-box;color: rgb(242, 44, 64);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"/></code></span></span></p> </li> <p style="margin: 10px auto;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 14px;white-space: normal;background-color: rgb(255, 255, 255);"><span style=" ; ; ">可以看到,現在我們每一次訪問 yimi 頁面,都會傳回一個當前時間。</span></p> <p style="margin: 10px auto;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 14px;white-space: normal;background-color: rgb(255, 255, 255);text-align: center;"><img class="" data-ratio="0.8358662613981763" data-type="png" data-w="329" src="https://res.cloudinary.com/dhk2edkft/image/upload/v1551258201/srbul82awitj5uofbofb.jpg" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 900px;"/></p> <p style="margin: 10px auto;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 14px;white-space: normal;background-color: rgb(255, 255, 255);text-align: center;"><img class="" data-ratio="0.886435331230284" data-type="png" data-w="317" src="https://res.cloudinary.com/dhk2edkft/image/upload/v1551258206/s2noo4lqpxvvf3v7qgei.jpg" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 900px;"/></p> <h1 style="margin-top: 10px;margin-bottom: 10px;font-size: 28px;font-weight: bold;line-height: 1.5;font-family: Verdana, Arial, Helvetica, sans-serif;white-space: normal;background-color: rgb(255, 255, 255);"><span style="background-color: rgb(51, 204, 204);"> 小結一下</span></h1> <p style="margin: 10px auto;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 14px;white-space: normal;background-color: rgb(255, 255, 255);"><span style=" ; ; ">1. web 框架的本質:</span><br /><span style=" ; ; ">  socket 服務端 與 瀏覽器的通信</span><br /><span style=" ; ; ">2. socket 服務端功能劃分:</span><br /><span style=" ; ; ">  a. 負責與瀏覽器收發訊息( socket 通信) --> wsgiref/uWsgi/gunicorn...</span><br /><span style=" ; ; ">  b. 根據用戶訪問不同的路徑執行不同的函式</span><br /><span style=" ; ; ">  c. 從 HTML 讀取出內容,並且完成字串的替換 --> jinja2 (模板語言)</span><br /><span style=" ; ; ">3. Python 中 Web 框架的分類:</span><br /><span style=" ; ; ">  1. 按上面三個功能劃分:</span><br /><span style=" ; ; ">    1. 框架自帶 a,b,c --> Tornado</span><br /><span style=" ; ; ">    2. 框架自帶 b 和 c,使用第三方的 a --> <strong>Django</strong></span><br /><span style=" ; ; ">    3. 框架自帶 b,使用第三方的 a 和 c --> Flask</span><br /><span style=" ; ; ">  2. 按另一個維度來劃分:</span><br /><span style=" ; ; ">    1. Django --> 大而全(你做一個網站能用到的它都有)</span><br /><span style=" ; ; ">    2. 其他 --> Flask 輕量級</span></p> <h1 style="margin-top: 10px;margin-bottom: 10px;font-size: 28px;font-weight: bold;line-height: 1.5;font-family: Verdana, Arial, Helvetica, sans-serif;white-space: normal;background-color: rgb(255, 255, 255);"><span style="background-color: rgb(51, 204, 204);">引入 wsgiref 模塊實現 socket 通信</span></h1> <p style="margin: 10px auto;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 14px;white-space: normal;background-color: rgb(255, 255, 255);text-indent: 2em;"><span style=" ; ; ">不知道你會不會覺得之前的程式中,socket 通信特別麻煩,而且還都是一樣的套路,完完全全可以獨立出來做成一個模塊,要用的時候再直接引進來用就可以了。</span></p> <p style="margin: 10px auto;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 14px;white-space: normal;background-color: rgb(255, 255, 255);text-indent: 2em;"><span style=" ; ; ">沒錯,有你這種想法的人還不在少數(吃鯨......),特別是一些大牛們,就 socket 通信這一塊,做出了一些特別好用的模塊,例如我們下麵要用的 wsgiref 模塊。</span></p> <ol class="linenums list-paddingleft-2" style="list-style-type: none;"> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"""</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">根據URL中不同的路徑傳回不同的內容--函式進階版</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">傳回HTML頁面</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">讓網頁動態起來</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">wsgiref模塊負責與瀏覽器收發訊息(socket通信)</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"""</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"/></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">import</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> time</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">from</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> wsgiref</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">.</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">simple_server </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">import</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> make_server</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"/></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"/></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="com" style="box-sizing: border-box;color: rgb(156, 148, 145);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"># 將傳回不同的內容部分封裝成函式</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">def</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> yimi</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">(</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">url</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">):</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">with</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> open</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">(</span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"yimi.html"</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">,</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> </span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"r"</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">,</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> encoding</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"utf8"</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">)</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">as</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> f</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">:</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">        s </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> f</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">.</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">read</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">()</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">        now </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> str</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">(</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">time</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">.</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">ctime</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">())</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">        s </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> s</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">.</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">replace</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">(</span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"@@xx@@"</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">,</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> now</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">)</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">return</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> bytes</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">(</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">s</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">,</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> encoding</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"utf8"</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">)</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"/></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"/></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">def</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> xiaohei</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">(</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">url</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">):</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">with</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> open</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">(</span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"xiaohei.html"</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">,</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> </span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"r"</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">,</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> encoding</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"utf8"</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">)</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">as</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> f</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">:</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">        s </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> f</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">.</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">read</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">()</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">return</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> bytes</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">(</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">s</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">,</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> encoding</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"utf8"</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">)</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"/></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"/></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="com" style="box-sizing: border-box;color: rgb(156, 148, 145);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"># 定義一個url和實際要執行的函式的對應關係</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">list1 </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">[</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">(</span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"/yimi/"</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">,</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> yimi</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">),</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">(</span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"/xiaohei/"</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">,</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> xiaohei</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">),</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">]</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"/></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"/></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">def</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> run_server</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">(</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">environ</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">,</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> start_response</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">):</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    start_response</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">(</span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">'200 OK'</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">,</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">[(</span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">'Content-Type'</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">,</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> </span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">'text/html;charset=utf8'</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">),</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">])</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">  </span><span class="com" style="box-sizing: border-box;color: rgb(156, 148, 145);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"># 設置HTTP響應的狀態碼和頭信息</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    url </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> environ</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">[</span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">'PATH_INFO'</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">]</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">  </span><span class="com" style="box-sizing: border-box;color: rgb(156, 148, 145);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"># 取到用戶輸入的url</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    func </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">None</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">for</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> i </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">in</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> list1</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">:</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">        </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">if</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> i</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">[</span><span class="lit" style="box-sizing: border-box;color: rgb(223, 83, 32);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">0</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">]</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">==</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> url</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">:</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">            func </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> i</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">[</span><span class="lit" style="box-sizing: border-box;color: rgb(223, 83, 32);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">1</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">]</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">            </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">break</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">if</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> func</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">:</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">        response </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> func</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">(</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">url</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">)</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">else</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">:</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">        response </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> b</span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"</p> <h1>404 not found!</h1> <p>"</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">return</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">[</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">response</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">,</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">]</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"/></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"/></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">if</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> __name__ </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">==</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> </span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">'__main__'</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">:</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    httpd </span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">=</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> make_server</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">(</span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">'127.0.0.1'</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">,</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> </span><span class="lit" style="box-sizing: border-box;color: rgb(223, 83, 32);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">8090</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">,</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;"> run_server</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">)</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    </span><span class="kwd" style="box-sizing: border-box;color: rgb(102, 102, 234);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">print</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">(</span><span class="str" style="box-sizing: border-box;color: rgb(123, 151, 38);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">"我在8090等你哦..."</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">)</span></code></span></span></p> </li> <li> <p><span style="box-sizing: border-box;color: rgb(74, 74, 74);display: block;line-height: 22px;font-size: 14px !important;word-break: inherit !important;"><span style="box-sizing: border-box;line-height: 22px;display: block;word-break: inherit !important;"><code style="box-sizing: border-box;margin-left: -20px;display: flex;overflow: initial;line-height: 12px;word-wrap: normal;border-width: 0px;border-style: initial;border-color: initial;font-size: 10px;font-family: inherit !important;white-space: pre !important;"><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">    httpd</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">.</span><span class="pln" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">serve_forever</span><span class="pun" style="box-sizing: border-box;color: rgb(27, 25, 24);line-height: 20px;font-size: 13px !important;white-space: inherit !important;">()</span></code></span></span></p> </li> </ol> <p style="margin: 10px auto;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 14px;white-space: normal;background-color: rgb(255, 255, 255);"><span style=" ; ; ">你會發現,使用了 wsgiref 模塊之後,程式封裝更好了,代碼邏輯也更加清晰了。</span></p> <p style="margin: 10px auto;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 14px;white-space: normal;background-color: rgb(255, 255, 255);text-align: center;"><img class="" data-ratio="0.7112860892388452" data-type="png" data-w="381" src="http://pic.ipshop.xyz/wx/Ab328bkWEXu.jpg" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 900px;"/></p> <p style="margin: 10px auto;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 14px;white-space: normal;background-color: rgb(255, 255, 255);"><img class="" data-backh="126" data-backw="839" data-before-oversubscription-url="https://img.chuansongme.com/mmbiz_png/Kad3LZzM7n53jZibw9CKOWFZF2Ankvib89HqyrJuMF1IKaV2SOqsibNw3FqpYb1HPcv58X27Xia2jh1tENxYNMvoqw/?wx_fmt=png" data-oversubscription-url="https://img.chuansongme.com/mmbiz_jpg/Kad3LZzM7n53jZibw9CKOWFZF2Ankvib89NR2yL7z0pdx7lf1f0ZnQDLhyu8N3FeNHl86OklbAZicqmUIK2W3MmEw/0?wx_fmt=jpeg" data-ratio="0.1501787842669845" data-type="png" data-w="839" src="https://res.cloudinary.com/dhk2edkft/image/upload/v1551258282/r0f0fwhxt34nbfkefsdc.jpg" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 900px;width: 100%;height: auto;"/></p> <h1 style="margin-top: 10px;margin-bottom: 10px;font-size: 28px;font-weight: bold;line-height: 1.5;font-family: Verdana, Arial, Helvetica, sans-serif;white-space: normal;background-color: rgb(255, 255, 255);"><span style="background-color: rgb(51, 204, 204);"> WSGI 協議</span></h1> <p style="margin: 10px auto;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 14px;white-space: normal;background-color: rgb(255, 255, 255);text-indent: 2em;"><span style=" ; ; ">經過上面的 wsgiref 模塊的示例,在使用通信模塊的方便之餘,你可能已經意識到一個問題,類似於 wsgiref 這樣的模塊肯定不止一個,我們自己寫的 url 處理函式需要和這些模塊進行通信,那麼,我怎麼知道這些模塊傳過來的信息是什麼格式?如果各個模塊傳過來的信息結構都不一樣的話,那豈不是說我得根據每一個模塊去定製它專門的 url 處理函式?這不科學,這中間肯定需要一個協議進行約束,這個協議,就叫<strong> WSGI 協議</strong>。</span></p> <p style="margin: 10px auto;font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 14px;white-space: normal;background-color: rgb(255, 255, 255);"><img class="" data-backh="32" data-backw="142" data-before-oversubscription-url="https://img.chuansongme.com/mmbiz_png/Kad3LZzM7n53jZibw9CKOWFZF2Ankvib89iaAC1CMJraTiakiaKpu7WSXjiaPmricnfziaRvDI4d4SPZ7iaMrWmr8u9auZw/?wx_fmt=png" data-ratio="0.22878932316491898" data-type="png" data-w="1049" src="https://res.cloudinary.com/dhk2edkft/image/upload/v1551258285/odw2znvglzp3ru1hurak.jpg" style="border-width: 0px;border-style: initial;border-color: initial;max-width: 900px;width: 100%;height: auto;"/></p> <section class="_editor"> <section style="border-width: 0px;border-style: none;border-color: initial;box-sizing: border-box;"> <section style="padding: 10px;box-sizing: border-box;"> <section style="padding: 10px;background-color: #0076b4;box-sizing: border-box;"> <section style="padding: 10px;border-width: 2px;border-style: dashed;border-color: #ffffff;font-size: 14px;color: #ffffff;box-sizing: border-box;"> <p>作者:守護窗明守護愛</p> <p>源自:</p> <p>http://www.cnblogs.com/chuangming/p/9072251.html</p> </section> </section> <section data-width="100%" style="width:100%;text-align:center;margin-top:-15px;"> <section style="display:inline-block;width:100px;height:10px;background-color:#afafaf;"/></section> </section> </section> </section> <div class="ct_mpda_wrp" id="js_sponsor_ad_area" style="display:none;"/> <div class="reward_area tc reward_area_primary" id="js_preview_reward_author" style="display:none;"> <div class="reward-avatar" id="js_preview_reward_author_avatar" style="display: none;"> <img alt="" id="js_preview_reward_author_head" src=""/> </div> <div class="reward-author" id="js_preview_reward_author_name">守護窗明守護愛</div> <p class="reward_tips" id="js_preview_reward_author_wording" style="display:none;"/> <p> <a class="reward_button" csmlink="h3lNPc" href="http://chuansongme.com/r/h3lNPc" id="js_preview_reward_author_link" rel="nofollow"><span id="js_preview_reward_link_text">贊賞</span></a> </p> </div> <div class="reward_qrcode_area reward_area tc" id="js_preview_reward_qrcode" style="display:none;"> <p class="tips_global">長按二維碼向我轉賬</p> <p class="reward_tips" id="js_preview_reward_ios_wording" style="display:none;"/> <span class="reward_qrcode_img_wrp"><img class="reward_qrcode_img" src="//res.wx.qq.com/mmbizwap/zh_CN/htmledition/images/pic/appmsg/pic_reward_qrcode.2x3534dd.png"/></span></p> <p class="tips_global">受蘋果公司新規定影響,微信 iOS 版的贊賞功能被關閉,可通過二維碼轉賬支持公眾號。</p> </div> <ul class="article_extend_area" id="js_hotspot_area"/> <div class="rich_media_tool" id="js_toobar3"> </div> <div class="weui-desktop-popover weui-desktop-popover_pos-up-center weui-desktop-popover_img-text" id="js_pc_weapp_code" style="display: none;"> <div class="weui-desktop-popover__content"> <div class="weui-desktop-popover__desc"> <img id="js_pc_weapp_code_img"/><br /> 微信掃一掃<br />使用小程式<span id="js_pc_weapp_code_des"/> </div> </div> </div> <div id="js_minipro_dialog" style="display:none;"> <div class="weui-mask"/> <div class="weui-dialog"> <div class="weui-dialog__bd">即將打開"<span id="js_minipro_dialog_name"/>"小程式</div> <div class="weui-dialog__ft"> <a class="weui-dialog__btn weui-dialog__btn_default" href="javascript:void(0);" id="js_minipro_dialog_cancel">取消</a><br /> <a class="weui-dialog__btn weui-dialog__btn_primary" href="javascript:void(0);" id="js_minipro_dialog_ok">打開</a> </div> </div> </div> </div> </article> <div class="post-actions"> <a href="javascript:;" class="post-like action action-like" data-pid="7635"><i class="fa fa-thumbs-o-up"></i>赞(<span>0</span>)</a> </div> <div class="action-share"></div> <div class="article-tags">标签:<a href="https://www.ipshop.xyz/tag/ios" rel="tag">iOS</a><a href="https://www.ipshop.xyz/tag/python" rel="tag">Python</a></div> <nav class="article-nav"> <span class="article-nav-prev">上一篇<br><a href="https://www.ipshop.xyz/7634.html" rel="prev">關係型資料庫為什麼能活這麼久?</a></span> <span class="article-nav-next">下一篇<br><a href="https://www.ipshop.xyz/7636.html" rel="next">Bruce Eckel:我最喜歡Python,Kotlin或將取代Java(附演講全文+PPT)</a></span> </nav> <div class="relates"><div class="title"><h3>相關推薦</h3></div><ul><li><a href="https://www.ipshop.xyz/18292.html">分庫分表實戰:可能是用戶表最佳分庫分表方案</a></li><li><a href="https://www.ipshop.xyz/18291.html">4 張 GIF 圖幫助你理解二叉搜索樹</a></li><li><a href="https://www.ipshop.xyz/17827.html">分佈式鏈路追蹤 SkyWalking 原始碼分析 —— Agent 收集 Trace 資料</a></li><li><a href="https://www.ipshop.xyz/17784.html">一份來自英偉達的越南小姐姐整理的機器學習入門清單,照這樣學就對了</a></li><li><a href="https://www.ipshop.xyz/17854.html">HBase 資料遷移方案介紹</a></li><li><a href="https://www.ipshop.xyz/17853.html">C# 管道式編程</a></li><li><a href="https://www.ipshop.xyz/17787.html">不會SQL註入,連漫畫都看不懂了</a></li><li><a href="https://www.ipshop.xyz/17782.html">向Excel說再見,神級編輯器統一表格與Python</a></li></ul></div> </div> </div> <div class="sidebar"> <div class="widget widget_ui_asb"><div class="item"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- ad3 --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-3715363832600463" data-ad-slot="8216000168" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script></div></div><div class="widget widget_ui_tags"><h3>熱門標籤</h3><div class="items"><a href="https://www.ipshop.xyz/tag/ios">iOS (11238)</a><a href="https://www.ipshop.xyz/tag/%e5%be%ae%e8%bb%9f">微軟 (4955)</a><a href="https://www.ipshop.xyz/tag/linux">Linux (4274)</a><a href="https://www.ipshop.xyz/tag/%e5%ae%89%e5%85%a8">安全 (4180)</a><a href="https://www.ipshop.xyz/tag/python">Python (4160)</a><a href="https://www.ipshop.xyz/tag/%e6%80%a7%e8%83%bd">性能 (3165)</a><a href="https://www.ipshop.xyz/tag/%e9%81%8b%e7%b6%ad">運維 (2774)</a><a href="https://www.ipshop.xyz/tag/%e5%84%aa%e5%8c%96">優化 (2419)</a><a href="https://www.ipshop.xyz/tag/net">.NET (2262)</a><a href="https://www.ipshop.xyz/tag/google">Google (2136)</a><a href="https://www.ipshop.xyz/tag/%e6%a9%9f%e5%99%a8%e5%ad%b8%e7%bf%92">機器學習 (1795)</a><a href="https://www.ipshop.xyz/tag/%e4%bd%b5%e7%99%bc">併發 (1613)</a><a href="https://www.ipshop.xyz/tag/%e5%88%86%e4%bd%88%e5%bc%8f">分佈式 (1559)</a><a href="https://www.ipshop.xyz/tag/%e9%9b%86%e7%be%a4">集群 (1240)</a><a href="https://www.ipshop.xyz/tag/sql">SQL (1174)</a><a href="https://www.ipshop.xyz/tag/mysql">Mysql (1058)</a><a href="https://www.ipshop.xyz/tag/%e5%8d%80%e5%a1%8a%e9%8f%88">區塊鏈 (1017)</a><a href="https://www.ipshop.xyz/tag/docker">Docker (977)</a><a href="https://www.ipshop.xyz/tag/%e5%be%ae%e6%9c%8d%e5%8b%99">微服務 (922)</a><a href="https://www.ipshop.xyz/tag/%e9%9d%a2%e8%a9%a6">面試 (919)</a><a href="https://www.ipshop.xyz/tag/apache">Apache (743)</a><a href="https://www.ipshop.xyz/tag/nlp">NLP (725)</a><a href="https://www.ipshop.xyz/tag/redis">Redis (719)</a><a href="https://www.ipshop.xyz/tag/android">Android (668)</a><a href="https://www.ipshop.xyz/tag/git">Git (640)</a><a href="https://www.ipshop.xyz/tag/%e6%9e%b6%e6%a7%8b%e5%b8%ab">架構師 (632)</a><a href="https://www.ipshop.xyz/tag/nginx">Nginx (630)</a><a href="https://www.ipshop.xyz/tag/facebook">Facebook (599)</a><a href="https://www.ipshop.xyz/tag/jvm">JVM (595)</a><a href="https://www.ipshop.xyz/tag/%e7%88%ac%e8%9f%b2">爬蟲 (476)</a></div></div><div class="widget widget_ui_posts"><h3>热门文章</h3><ul class="nopic"><li><a href="https://www.ipshop.xyz/15779.html"><span class="text">用 docker-compose 啟動 WebApi 和 SQL Server</span><span class="muted">2019-06-26</span></a></li> <li><a href="https://www.ipshop.xyz/12632.html"><span class="text">小樣本學習(Few-shot Learning)綜述</span><span class="muted">2019-04-01</span></a></li> <li><a href="https://www.ipshop.xyz/1250.html"><span class="text">實體 :手把手教你用PyTorch快速準確地建立神經網絡(附4個學習用例)</span><span class="muted">2019-02-02</span></a></li> <li><a href="https://www.ipshop.xyz/9049.html"><span class="text">電線電纜的平方數及平方數和電流的換算公式</span><span class="muted">2018-04-02</span></a></li> <li><a href="https://www.ipshop.xyz/4542.html"><span class="text">黎曼猜想仍舊,素數依然孤獨</span><span class="muted">2018-09-26</span></a></li> <li><a href="https://www.ipshop.xyz/12129.html"><span class="text">Wexflow:C#中的開源工作流引擎</span><span class="muted">2019-03-22</span></a></li> </ul></div></div></section> <div class="branding branding-black"> <div class="container"> <h2>分享創造快樂</h2> </div> </div> <footer class="footer"> <div class="container"> <p>© 2021 <a href="https://www.ipshop.xyz">知識星球</a>   <a href="http://www.ipshop.xyz/sitemap.xml">网站地图</a> </p> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-133465382-1"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-133465382-1'); </script> </div> </footer> <script> window.jsui={ www: 'https://www.ipshop.xyz', uri: 'https://www.ipshop.xyz/wp-content/themes/dux', ver: '5.0', roll: [], ajaxpager: '0', url_rp: '', qq_id: '', qq_tip: '' }; </script> <script type='text/javascript' src='https://www.ipshop.xyz/wp-content/themes/dux/js/libs/bootstrap.min.js?ver=5.0'></script> <script type='text/javascript' src='https://www.ipshop.xyz/wp-content/themes/dux/js/loader.js?ver=5.0'></script> <script type='text/javascript' src='https://www.ipshop.xyz/wp-includes/js/wp-embed.min.js?ver=4.9.16'></script> </body> </html><script data-cfasync="false" src="/cdn-cgi/scripts/5c5dd728/cloudflare-static/email-decode.min.js"></script>