📜 ⬆️ ⬇️

Web2py framework

I am not the inventor of the next rover bike, but just want to tell about the python framework WEB2PY. On Habré for some reason there are no articles about this wonderful tool. If it is interesting, under habrakat a small history of use of web2py and its description.

Having started studying the framework, I was able to create several serious projects, received a profit from their sales ... and continue to receive income from their maintenance and refinement. This activity influenced my attitude to life and ... well, everything was in order.


')
The background is such that one day a friend called me, told me about the “work” at the checkpoint (common people, “customs”) and asked if I could find / offer / write him a “simple” vehicle registration program. in the zone of the customs post. From his confused story, I was able to determine only the basic requirements for the project:


I already wanted to stop the conversation, but the magic phrase “say how much money you need - we will pay” did the trick, and I said: “Eeeeh, okay,” I began to look for options.

My logic was simple:
What is my favorite programming language?


How to quickly make a cross-platform application running on any hardware?


How to bypass the restriction of customs rules at the post and optimize the installation of the application in the existing local network?


how to be with base?



This nontrivial task, at first glance, turned out to be easily solvable. The answer is web2py. At that time I did not know anything about this framework. But if there is a desire and obstinacy, then nothing is impossible! Besides, I really wanted to test my skills in writing applications for mass use.

On the project site we download the latest version, unpack the archive - and almost everything is ready! The root directory has web2py.exe for win, web2py.app for osx, and you can also run the project like this: python web2py.py . At startup, you should specify the server password, IP and port (by default 8000). After launch, you can open a browser and go to the IP: port server address.

The ready-made test project welcome will start.


By clicking on the ADMINISTRATIVE INTERFACE button, we are taken to the admin area, where you can manage sites.


Sites are stored separately from each other in the APPLICATIONS directory. When creating a new site, a new directory is automatically created with the site name and the required directory structure is formed. If the new site is called INIT, then it will be launched automatically at the start: http://192.168.0.2:8000 . If you want to open some other site, then you just need to specify its name, for example: http://192.168.0.2:8000/welcome .

Understanding how web2py works is very easy. It is important to understand that to work you need to manipulate the three main components:


In db.py , a connection to the database is defined and the necessary tables are created, for example:
db=DAL('sqlite://storage.db') #   db.define_table('image', #     image Field('name'), #   Field('file','upload')) #    


In the default.py controller, we write python functions, for example:
 def index(): form = SQLFORM(db.image) #      image if form.process().accepted: #,   ,  response.flash = 'image uploaded' #  return dict(form = form) # ,     


To display the result of the function in the browser, you need to create an html document with the name of the function in the views / default directory, for example:
 {{extend 'layout.html'}} #    <h1>Image upload form</h1> {{form}} #  


Here is the result of these simple manipulations:

Select the file and save it to the database. I think that simply can not be easier!

The sqlite3 database works out of the box, besides it allows you to connect PostgreSQL, MySQL, MSSQL, FireBird, Oracle, IBM DB2, Informix, Ingres, and Google App Engine.

In the process of writing code, I did not have any serious problems. The framework site has a section with detailed documentation and examples ! Everything is in English. The framework also has its own google group, web2py-users (by the way, the level and speed of responses are sometimes just surprising!). A deep and meaningful reading of the documentation gave its results, and in about a month I had a working system ready, which we successfully implemented. The introduction is of course, loudly said. I just handed the catalog on a flash drive, which I had to put on the server and run the batch file. As a server, people themselves bought some PC station. Fortunately, people got to understand and knew how to find out / set / change the IP address, how to start the service and go to the browser at the address indicating the port. And then I thought it would be the most difficult task.

Now I can say with confidence that the system has been working for more than two years. Nobody fits the server (well, except for blowing dust), there are no errors, the average number of simultaneous connections is about 50, maintenance is not needed, everyone is happy. Thus, I “pumped up” my skills after learning a lot in python; got experience in communication and correspondence in English; earned money in the end. None of this could have been possible if it were not for confidence in success and constant thirst for knowledge. After this project, I received another order, then more and more ...

PS
I am glad that my first starting topic on Habré is dedicated to web2py!

Pps
With this topic, I once again want to send many of us to the course. On Habré, there are many topics about the need to learn English, about coursera on-line courses (I am passing the third course, recorded two more), about other types of personal development stimulation. I want to say that it really works! Verified by personal experience.

Source: https://habr.com/ru/post/149357/


All Articles