最新消息:关注【太平洋学习网】微信公众号,可以获取全套资料,【全套Java基础27天】【JavaEE就业视频4个月】【Android就业视频4个月】

python web hello world入门学习案例

扩展 太平洋学习网 浏览 评论

 python开发web网页项目也是非常流行的,而且python的语言代码简洁,我感觉以后也会在web上占一席之地,特意供上python web hello world入门学习案例,体验一下python web开发。

新建hello.py文件,本人用的是pycharm开发工具,非常的好用。

from wsgiref.simple_server import make_server

def hello_worlds(environ, start_response):
    status = "200 OK"
    headers = [("Content-type", "text/plain")]
    # start_response("200 OK", [('Content-Type', 'text/plain; charset=utf-8')])
    start_response(status, headers)
    return ["hello world".encode("utf-8")]

httpd = make_server('', 8080, hello_worlds)
print("Server on port 8080")
httpd.serve_forever()

右键运行之后在浏览器输入http://localhost:8080就可以在浏览器输出“hello world”了,这个会启动python自带的 wsgi web服务器,正式开发中使用Tornado应用服务器,可以将python web部署在Tornado上

来源网站:太平洋学习网,转载请注明出处:http://www.tpyyes.com/a/kuozhan/182.html
"文章很值,打赏犒劳作者一下"
微信号: Javaweb_engineer

打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

与本文相关的文章

发表我的评论
取消评论

表情

您的回复是我们的动力!

  • 昵称 (必填)

网友最新评论