Web2py Framework in Python
In the following tutorial, we will understand the Web2py framework in the Python programming language.
Understanding the Web2py Framework
Web2py is an easy-to-use framework that does not require any installation and configuration. This framework is portable and can also be executed on a USD drive. It is based on the MVC framework like many other Python frameworks. Though most of them do not support older versions of the Python programming language, the Web2py framework still supports versions like Python 2.6 and 2.7. It also supports LDAP for authentication, which is widely accepted these days.
The Web2py framework attempts to lower the barrier of entry to web development by focusing on three chief goals:
Acknowledging the perspective of the user, the Web2py framework is developed and constantly being optimized internally in order to make it a faster and leaner framework with the inclusion of the support for backward compatibility.
Setting Up the Environment
Execution of the Web2py framework is easy, and we need to download the .exe file from the following link:
For Windows, we can download the ZIP file, unzip it, and execute the .exe file either directly or from the command line. We will be prompted with the screen asking for the admin password as shown below:
We can choose an administrator password and start the server. We will see the following screen:
Creating an application using Web2py
Let us now create a new application with the help of the Python Web2py framework. We will start by clicking on the admin table located at the bottom. So, after entering the admin password, we will have the following screen:
Now, go to new simple application, enter some application name (for example, introWeb2py) and click on create. This will display design interface page as shown below:
We can also go to the current live web, introWeb2py, and simply type http://127.0.0.1:8000/introWeb2py on the local machine, and we will get the output as shown below:
In the design page of the introWeb2py application, we will go to the controller and click on the edit button next to default.py. If we alter the return value of the index() function, the following output will be displayed.
Now, let us save the changes. We can check the changes made in the introWeb2py application by refreshing the http://127.0.0.1:8000/introWeb2py link. The output for the same is shown below:
Deployment of the application on the Cloud platform
If we want to deploy the application on the Cloud platform, we will go back to the home page and click on the site. We can select any option for deployment. Here, we will select "pythonAnywhere". We will then go to the pythonAnywhere website and register ourselves (if not done already). We will then click on "Add a new web app" and fill in all the credentials (Select web2py app). That's it.
We will go to https://username.pythonanywhere.com/welcome/default/index, and click on the admin tab (enter password). Next, we will click on upload and install the packed application. We have to fill in the credentials below and click install.
Once everything is completed, a pop-up message will appear. In order to view the application, open the below link:
https://username.pythonanywhere.com/welcome/default/index and we can see the following screen.
Hence, the first web2py application is created and deployed successfully.
At last, we can conclude the Web2py framework is a free, fast, secure web development framework that is entirely written in the Python programming language and encourages with the help of Python in every way possible (model, view, controller). It is a very good framework for small web applications or prototypes; however, it fails to fulfill the enterprise-class quality requirements. In an enterprise-level application, the complexity of solving bugs will increase exponentially due to the lack of unit tests, good and accurate error reporting, and scattered models.
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week