web.py是一个轻量级的python web框架,简单而且功能强大。相对flask和Django,web.py更适合初学者来学习和了解web开发的基础知识。
我们首先来说一下web.py的安装
前提是已经安装了python环境(最新Python3.7)
web.py的官方网站:/, 可以看看文档,有介绍如何安装和入门教程
安装环境:
windouws7
python3.7.3
/webpy/webpy/tree/py3
下载到电脑上,然后解压到一个目录(任意都可以),打开cmd进入到解压的目录,如下:
然后cmd下进入上图,用以下命令完成安装:
python setup.py install
运行这个命令行,会输出如下:
D:\AI\python\web\webpy>python setup.py installC:\Users\AppData\Local\Programs\Python\Python36\lib\site-packages\setuptools\dist.py:355: UserWarning: Normalizing '0.40-dev0' to '0.40.dev0'normalized_version,running installrunning bdist_eggrunning egg_infowriting web.py.egg-info\PKG-INFOwriting dependency_links to web.py.egg-info\dependency_links.txtwriting top-level names to web.py.egg-info\top_level.txtreading manifest file 'web.py.egg-info\SOURCES.txt'writing manifest file 'web.py.egg-info\SOURCES.txt'installing library code to build\bdist.win-amd64\eggrunning install_librunning build_pycopying web\wsgiserver\wsgiserver2.py -> build\lib\web\wsgiservercreating build\bdist.win-amd64\eggcreating build\bdist.win-amd64\egg\webcopying build\lib\web\application.py -> build\bdist.win-amd64\egg\webcopying build\lib\web\browser.py -> build\bdist.win-amd64\egg\webcreating build\bdist.win-amd64\egg\web\contribcopying build\lib\web\contrib\template.py -> build\bdist.win-amd64\egg\web\contribcopying build\lib\web\contrib\__init__.py -> build\bdist.win-amd64\egg\web\contribcopying build\lib\web\db.py -> build\bdist.win-amd64\egg\webcopying build\lib\web\debugerror.py -> build\bdist.win-amd64\egg\webcopying build\lib\web\form.py -> build\bdist.win-amd64\egg\webcopying build\lib\web\http.py -> build\bdist.win-amd64\egg\webcopying build\lib\web\httpserver.py -> build\bdist.win-amd64\egg\webcopying build\lib\web\net.py -> build\bdist.win-amd64\egg\webcopying build\lib\web\py3helpers.py -> build\bdist.win-amd64\egg\webcopying build\lib\web\session.py -> build\bdist.win-amd64\egg\webcopying build\lib\web\template.py -> build\bdist.win-amd64\egg\webcopying build\lib\web\test.py -> build\bdist.win-amd64\egg\webcopying build\lib\web\utils.py -> build\bdist.win-amd64\egg\webcopying build\lib\web\webapi.py -> build\bdist.win-amd64\egg\webcopying build\lib\web\webopenid.py -> build\bdist.win-amd64\egg\webcopying build\lib\web\wsgi.py -> build\bdist.win-amd64\egg\webcreating build\bdist.win-amd64\egg\web\wsgiservercopying build\lib\web\wsgiserver\ssl_builtin.py -> build\bdist.win-amd64\egg\web\wsgiservercopying build\lib\web\wsgiserver\ssl_pyopenssl.py -> build\bdist.win-amd64\egg\web\wsgiservercopying build\lib\web\wsgiserver\wsgiserver2.py -> build\bdist.win-amd64\egg\web\wsgiservercopying build\lib\web\wsgiserver\wsgiserver3.py -> build\bdist.win-amd64\egg\web\wsgiservercopying build\lib\web\wsgiserver\__init__.py -> build\bdist.win-amd64\egg\web\wsgiservercopying build\lib\web\__init__.py -> build\bdist.win-amd64\egg\webbyte-compiling build\bdist.win-amd64\egg\web\application.py to application.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\browser.py to browser.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\contrib\template.py to template.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\contrib\__init__.py to __init__.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\db.py to db.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\debugerror.py to debugerror.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\form.py to form.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\http.py to http.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\httpserver.py to httpserver.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\net.py to net.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\py3helpers.py to py3helpers.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\session.py to session.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\template.py to template.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\test.py to test.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\utils.py to utils.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\webapi.py to webapi.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\webopenid.py to webopenid.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\wsgi.py to wsgi.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\wsgiserver\ssl_builtin.py to ssl_builtin.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\wsgiserver\ssl_pyopenssl.py to ssl_pyopenssl.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\wsgiserver\wsgiserver2.py to wsgiserver2.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\wsgiserver\wsgiserver3.py to wsgiserver3.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\wsgiserver\__init__.py to __init__.cpython-36.pycbyte-compiling build\bdist.win-amd64\egg\web\__init__.py to __init__.cpython-36.pyccreating build\bdist.win-amd64\egg\EGG-INFOcopying web.py.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFOcopying web.py.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFOcopying web.py.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFOcopying web.py.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFOzip_safe flag not set; analyzing archive contents...web.__pycache__.application.cpython-36: module references __file__web.__pycache__.debugerror.cpython-36: module references __file__creating 'dist\web.py-0.40.dev0-py3.6.egg' and adding 'build\bdist.win-amd64\egg' to itremoving 'build\bdist.win-amd64\egg' (and everything under it)Processing web.py-0.40.dev0-py3.6.eggremoving 'c:\users\appdata\local\programs\python\python36\lib\site-packages\web.py-0.40.dev0-py3.6.egg' (and everything under it)creating c:\users\appdata\local\programs\python\python36\lib\site-packages\web.py-0.40.dev0-py3.6.eggExtracting web.py-0.40.dev0-py3.6.egg to c:\users\appdata\local\programs\python\python36\lib\site-packagesweb.py 0.40.dev0 is already the active version in easy-install.pthInstalled c:\users\appdata\local\programs\python\python36\lib\site-packages\web.py-0.40.dev0-py3.6.eggProcessing dependencies for web.py==0.40.dev0Finished processing dependencies for web.py==0.40.dev0
在这之前需要先安装db和utils这两个工具包
pip install db
pip install utils
然后安装完成后进行demo测试:
创建如下测试代码的test-webpy.py文件:
import weburls = ('/(.*)', 'hello')app = web.application(urls, globals())class hello:def GET(self, name):if not name:name = 'World'return 'Hello, ' + name + '!'if __name__ == "__main__":app.run()
通过cmd 进入test-webpy.py所在目录里执行python test.py
命令就可以,输出结果如下:
然后就可以在浏览器中访问 http://0.0.0.0:8080/ 这里4个0表示,本机和别的机器都能访问,8080是端口
使用本机浏览器 http://127.0.0.1:8080 测试一下。这个网址查看输出结果如下:
——————————————————————————————————————
说明安装完成并测试成功