Web2py -------------- example of using web2py to write django, web2pydjango
Follow the previous article to create an app named polls.
The file structure is as follows:
Then web2py automatically adds some code to it.
We need to remove some, such as the controllers and defualt. py index methods;
Corresponding to default/index.html under the views folder
In fact, it is not difficult to see the ing between the controller and views of web2py.
Files under controller correspond to a folder under view (controllers/default. py corresponds to views/default/folder ),
The file method in controller corresponds to the. html file in the corresponding view folder (the index method of controllers/default. py corresponds to the view/default/index.html)
Then we will remove some irrelevant content from the c and v of the corresponding relationship.
As follows:
Is it refreshing?
Extend 'layout.html 'in view is a commonly used referenced template file, which is preset in web2py and does not need to be modified at present. Let's take a look at the effect.
Isn't it refreshing? The content of layout is outside the whiteboard. If you need other modifications, You need to modify the file, but it is not detailed here.
Django only returned a piece of text at the first time of index.
Here we only return to the view, and then use the engine rendering that comes with web2py.
Code under controller
The code in view is as follows:
Then we access http: // 127.0.0.1: 8000/polls/default/index
You will get the following
A lot of things are omitted here.
However, the following correspondence can be obtained from the complete url we provide:
Http: // baseurl/app/controller/function
I don't know if I can understand this address.
Then we can clearly understand the relationships between controllers, views, and URLs.
Homework after class:
Understanding
Relationship between controllers, views, and URLs