Follow the previous article we created a new app called polls
Then the file structure is as follows
Then web2py will automatically add some code to the inside.
We need to remove some, such as this controllers, Defualt.py's index method;
The corresponding is the Views folder under Default/index.html
In fact, it is not difficult to see Web2py controller and views of the corresponding relationship
The file under the controller corresponds to a folder under view (controllers/default.py corresponds to the views/default/folder),
The method of the file under the controller corresponds to the. html file in the view's corresponding folder (controllers/default.py's index method corresponds to the views/default/index.html view)
And then we cut off some irrelevant content from this correspondence's C and v.
As follows
Is it a lot fresher?
Where the view of the extend ' layout.html ' is a common reference to a template file, which is also web2py preset good, and currently do not need to modify, we look at the effect
is not more refreshing, outside the whiteboard is the content of the layout, if you need other changes, you need to modify this file, but here is not elaborate.
Django returns only one text at the first time of index.
We're just going to go back to view, and then use the web2py's own engine to render it.
Controller under Code
The code in view is as follows
Then we visit http://127.0.0.1:8000/polls/default/index
You will get the following
There are a lot of things omitted here.
But the following correspondence can be derived from the complete URL we give
Http://baseurl/app/controller/function
I don't know if I can understand this address.
Then we can clearly understand the relationship between controllers, views, URLs
After-school assignments:
Understand
Controllers,views, the relationship between URLs
Web2py--------------use Web2py to write Django examples--------build a voting app