In this class, we started web2py.
The documentation for web2py can be found in the web2py book; over the next week, we will go over the overview.
The code developed in class was posted in the oct-8-2018 branch of the web2py start app.
To get this code, proceed as follows:
Install the source package of web2py if you haven't done it already.
You should have, as a result, a web2py directory, with a file web2py.py into it.
Proceed as follows.
Go into the applications directory:
Get the code repository, into a directory called start:
git clone https://luca_de_alfaro@bitbucket.org/luca_de_alfaro/web2py_start.git start
Check out the oct-8-2018 branch:
cd start
git checkout oct-8-2018
To run the code, just go to the top-level directory, the one where web2py.py is, and do:
The final -e means, please log all the errors to the console.
As a summary, in class we learned the main control flow with which web2py answers a web request.
This flow is documented in the web2py book, chapter core, but here it is summarized:
- When the request is serviced, the first thing that runs are the models, in the models directory, in alphabetical order.
- The first model is db.py. This model defines the following very important things:
- The db object, which is used to talk to the database.
- The auth object, which is used for user authentication, and which we will use to figure out whether the user is logged in, what's the user email, etc.
- The session object, which is used to store data related to the user session.
- The second model is menu.py. This model just defines the menu in the top bar of the site.
- The third model is tables.py; for now it's empty, but we will put there the definitions of our database tables.
- Once the models run, the controller is run. A request to http://mysite/myapp/mycontroller/myfunc is serviced by the function myfunc, defined in the controller mycontroller.py of the application myapp.
- The controller produces as output a dictionary (it can produce also other things, such as a file download, but we will deal with that later).
- The dictionary is passed to a view, in views/mycontroller/myfunc.html . The view is a template, which is filled in with the information in the dictionary, creating an HTML page that is then sent back to the user.