python制作web⽹页实例_基于python实现简单⽹页服务器代
码实例
代码:
hello.py
#!/usr/bin/python
# coding: utf-8
# hello.py
def application(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])
return '
Hello, %s!
' % (environ['PATH_INFO'][1:] or 'web')
server.py
#!/usr/bin/python
# coding: utf-8
网页设计html代码例子# server.py
from wsgiref.simple_server import make_server
from hello import application
# create server, ip is empty, port is 8000, handle function is application
httpd = make_server('', 8000, application)
print "Serving HTTP on "
# start listen http request
httpd.serve_forever()
使⽤了模块wsgiref。它实现了wsgi接⼝,我们只需要定⼀个wsgi处理函数来处理得到的请求就可以了。
⽤python来实现这些看似很复杂的实例程序,⾮常简单,这都得益于python强⼤的库。
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持python博客。

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。