Python Web Development Libraries 简明教程
Web2py Framework
Web2py 是一款易于使用的框架。使用 web2py 无需安装和配置,因为它具有可移植性,且可以在 USD 驱动器中运行。它基于 MVC 框架,与许多其他 Python 框架相似。尽管大多数框架不支持旧版本的 Python,但 web2py 仍然支持旧版本:Python 2.6 和 2.7。它还支持 LDAP 认证,这是当今广泛接受的认证方式。
Web2py is an easy-to-use framework. With web2py, no installation and configuration is required as it is portable and can be run on a USD drive too. It is based on the MVC frameworks like many other python frameworks. Though most of them do not support older versions of Python, web2py still supports older versions: python 2.6 and 2.7. It also supports LDAP for authentication which is widely accepted these days.
Web2py 尝试通过关注三个主要目标降低 Web 开发的进入门槛 −
Web2py tries to lower the barrier of entry to web development by focusing on three main goals −
-
Rapid development
-
Ease of use
-
Security
考虑到用户观点,Web2py 会不断在内部进行优化以使其成为更快速、更精简的框架,包括对向后兼容性的支持。
Keeping in mind the user perspective, Web2py is built and constantly being optimized internally to make it a faster and leaner framework including support for backward compatibility.
Installing and Configuring Web2py Framework
运行一个 web2py 非常简单,你需从此链接下载 exe 文件: http://www.web2py.com/init/default/download
Running a web2py is easy, you need to download the exe from the below link: http://www.web2py.com/init/default/download
对于 Windows,你可以下载 zip 文件,将其解压,直接或通过命令行运行 exe 文件。系统会弹出如下屏幕,要求提供管理员密码。
For windows, you can download the zip file, unzip it and run the exe file either directly or from the command line. You will be prompted with below screen asking for the admin password.

你可以选择一个管理员密码并启动服务器。你将看到以下屏幕 −
You can choose an administrator password and start the server. You will see the following screen −

Creating an app using Web2py
现在我们准备创建一个新的应用程序。单击位于底部的 admin 标签。因此,输入管理员密码后,我们将看到以下屏幕 −
Now we are ready to create a new app. Click on the admin tab located at the bottom. So after entering the admin password, we will get the below screen −

转到新简单应用程序,输入一些应用程序名称(如 helloWeb2py),然后单击创建。这将显示如下所示的设计界面页面 −
Go to new simple application, enter some application name (like helloWeb2py) and click on create. This will display design interface page as given below −

你还可以访问当前的实时网络,helloWeb2py,只需在本地机器上输入 http://127.0.0.1:8000/helloWeb2py ,你将看到以下输出 −
You can also go to your current live web,helloWeb2py, simply type http://127.0.0.1:8000/helloWeb2py on your local machine, you will get the below output −

在 helloWeb2py 应用程序的设计页面中,转到控制器,然后单击 default.py 旁边的编辑按钮。如果你更改 index() 函数的返回值,将显示以下输出 −
In the design page of helloWeb2py application, go to the controller and click on edit button next to default.py. If you change the return value of the index() function, the following output will be displayed −

保存更改内容,现在你可以在 helloWeb2py 应用程序中查看所做的更改。只需刷新 http://127.0.0.1:8000/helloWeb2py 链接,你将看到以下输出 −
Save the changes, and now you can check the changes made in your helloWeb2py app. Just refresh the http://127.0.0.1:8000/helloWeb2py link and you will see the below output −

Deploying the app on cloud platform
现在,如果你想在云平台上部署你的应用程序,请返回主页并单击站点。你可以选择任何一种部署选项。在这里,我们选择“pythonAnywhere”。转到 pythonAnywhere 网站并注册(如果尚未注册)。单击 “Add a new web app” 并填写所有凭据(选择 web2py 应用程序)。大功告成。
Now if you want to deploy your app on cloud platform, come back to your home page and click on the site. You can choose any option for deployment. Here, we choose “pythonAnywhere”. Go to pythonAnywhere website and register yourself (if not already done). Click on “Add a new web app” and fill all the credentials (Choose web2py app). All done.
现在,转到 https://username.pythonanywhere.com/welcome/default/index ,单击 admin 标签(输入密码)。然后单击上传并安装打包的应用程序。按如下内容填写凭据并单击安装。
Now go to https://username.pythonanywhere.com/welcome/default/index, click on admin tab (enter password). Next click on upload and install packed application. Fill the credentials as below and click install.

一切都完成后,将出现一个如下所示的弹出消息 −
Once everything is done, a pop-up message will appear as given below −

现在,要查看你的应用程序,请打开以下链接 −
Now to view your app, open the below link −
https://username.pythonanywhere.com/welcome/default/index and you can see the following screen −

我们的第一个 web2py 应用程序已成功创建并部署。
Our first web2py application is successfully created and deployed.
总而言之,Web2py 是一种免费、快速、安全的 web 开发框架,完全用 python 编写,并且鼓励在各个方面(模型、视图、控制器)使用 python。这是一个非常适合小型 web 应用程序或原型的框架,但无法达到企业级质量要求。原因在于,在企业级应用程序中,由于缺乏单元测试、良好准确的错误报告和分散的模型,解决 bug 的复杂度将呈指数级增长。
To summarize, Web2py is a free, fast, secure web development framework that is entirely written in python and encourages using python in every way possible (model, view, controller). It is a very good framework for small web applications or prototypes but fails to fulfil the enterprise class quality requirements. It is because, in an enterprise level application, the complexity of solving bugs will increase exponentially because of the lack of unit tests, good and accurate error reporting and scattered model.