基于python實(shí)現(xiàn)簡(jiǎn)單網(wǎng)頁(yè)服務(wù)器代碼實(shí)例
代碼:
hello.py
#!/usr/bin/python# coding: utf-8# hello.pydef application(environ, start_response): start_response(’200 OK’, [(’Content-Type’, ’text/html’)]) return ’<h1>Hello, %s!</h1>’ % (environ[’PATH_INFO’][1:] or ’web’)
server.py
#!/usr/bin/python# coding: utf-8# server.pyfrom wsgiref.simple_server import make_serverfrom hello import application# create server, ip is empty, port is 8000, handle function is applicationhttpd = make_server(’’, 8000, application)print 'Serving HTTP on port 8000...'# start listen http requesthttpd.serve_forever()
使用了模塊wsgiref。它實(shí)現(xiàn)了wsgi接口,我們只需要定一個(gè)wsgi處理函數(shù)來(lái)處理得到的請(qǐng)求就可以了。
用python來(lái)實(shí)現(xiàn)這些看似很復(fù)雜的實(shí)例程序,非常簡(jiǎn)單,這都得益于python強(qiáng)大的庫(kù)。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. python中scrapy處理項(xiàng)目數(shù)據(jù)的實(shí)例分析2. Python中讀取文件名中的數(shù)字的實(shí)例詳解3. 在idea中為注釋標(biāo)記作者日期操作4. 通過(guò)Ajax方式綁定select選項(xiàng)數(shù)據(jù)的實(shí)例5. JSP頁(yè)面的靜態(tài)包含和動(dòng)態(tài)包含使用方法6. ASP.Net Core對(duì)USB攝像頭進(jìn)行截圖7. ASP.NET MVC使用Boostrap實(shí)現(xiàn)產(chǎn)品展示、查詢(xún)、排序、分頁(yè)8. .net如何優(yōu)雅的使用EFCore實(shí)例詳解9. 使用AJAX(包含正則表達(dá)式)驗(yàn)證用戶(hù)登錄的步驟10. ajax動(dòng)態(tài)加載json數(shù)據(jù)并詳細(xì)解析
