Web2py -------------- example of using web2py to write django, web2pydjango
We created a data model and then presented the page this time.
1. Here is the control of the List page.
Here is the dal syntax
There are only two rows
The first line is to query all the problems, that is, the problem id is greater than 0.
The second row is the list of returned problems.
Here is the view
In view, we only need a for loop to show all the data,
However, you need to use if to determine whether it is empty.
Note:
Each logic tag such as {if }{{ for} is followed by a colon (:) And the paired {pass} Tag ends.
It is precisely because of these labels that there is no bottom line to write web2py just like writing php, And you can directly use functions in view ..
We have already written the data layer and will not modify it here.
The following is a page
The red part is the data we found from the database. If you ask me why there are two items, I won't tell you how to add them. Let's take a look at the previous tutorial.
2. Then detial is the details page.
Here is the content written by control.
Make a simple explanation,
First, the first request parameter is actually the question id,
Second, query the problem.
The third sentence is to query the answer to this question.
We will return questions and question options to the front-end
Is it simple and clear?
View
The specific tag is not used for any purpose. It means that I have indented it when I finish writing it, but now it's gone. However, only form has a inclusion relationship, and there is nothing complicated.
Yes, the next step is a small presentation. Do I think it is still harmonious?
3. Verification
You may find that one of them uses a function such as a URL ().
This is the function generated to splice the addresses. The default parameters are app, controller, and view, and the parameters are added.
The controller for this verification does not correspond to the view
So there is only one controller
The Code is as follows:
Where will the redirect () function redirect to results,
4. view the results. results
If it is not a small tutorial, this is definitely a redundant code, but it is also well maintained, there is no complicated content, sometimes some redundancy is also good, but it cannot be redundant. For details, refer to the detail section.
This is interesting. The django tutorial makes a close judgment on whether it is a plural number. If I did not ask, I forgot what the tag was doing, in this case, is the view exceptionally eye-catching?
Let's take a look at the final effect.
Now the official example provided by django has been completed,
The rest of the content is about cbv, but web2py does not support
So this tutorial is just an introduction,
I just want to tell you that,
However, every framework has its own merits. For example, if there is a need, it can be based on the advantages of web2py. Both the amount of code and the effect will be much better than this.
Now, bye-bye.
If you have any questions, you can send a private message or leave a message.