Web2py--------------use Web2py to write Django Examples--------build a poll application (3)

Source: Internet
Author: User
Tags django tutorial web2py

We built the data model, and this time we're going to show the page.

1, here is the control of the list page

Here's the DAL syntax.

Only two lines

The first line is to query for all problems, that is, the ID of the problem is greater than 0

The second line is the list of returned questions

Here is the view

We only need a for loop in view to actually show all the data,

But you need to use if to determine whether it is empty, attentive to deal with the situation is not empty

Attention:

Logical label for each {{if}} {{for}}, followed by a ': ' Colon, and a paired {{pass}} tag declares his end

It is because of these tags, like write web2py and write PHP without the bottom line, directly in the view of the use of functions.

Data layer We've already written it, and we're not making any changes here.

Here is the Display page

The red part is the data we looked up from the database, asked why I have two, I will not tell you, I have added a few, how to add, you can go to see the previous tutorial

2, then detial is the details page

This is what control writes.

To make a simple explanation,

In the first sentence, the first parameter of the request is actually the ID of the question,

The second sentence, query out the problem

The third sentence, query the answer to this question

We return questions to the front desk, and problem options

Is it simple and clear?

Here is the view

The specific label does not say what to do with, say I finished writing when there is indentation, but, now No. But only form has a relationship, and there's nothing complicated.

Yes, the next little show, I think it's still very harmonious.

3. Verification link

A careful classmate will find that there is a function that uses a URL ()

This is the function for stitching the address, the corresponding default parameters are App,controller,view, and then add the parameters

This validated controller does not correspond to the view

So there's only one controller.

The code is as follows

Redirect () function will redirect to results where,

4. Results View Results

Do not say, if it is not a small tutorial, this is definitely a redundant code, but also very good maintenance, no complicated content, sometimes some redundancy is good, but can not be said to be redundant see the detail section

This is interesting, Django tutorial intimate judgment is not a plural, anyway, if not ask, I also forget what the label is doing, so that the view is not particularly glaring?

Let's take a look at the final effect

Okay, now the official Django example is done,

The rest of it is about CBV, but Web2py doesn't support

So this tutorial is an introduction,

Just to tell you that the same

But each framework has its own desirable things, such as if there is a demand, can be in accordance with the web2py of its own advantages, whether it is the amount of code, or the effect, will be much better than this.

Now that's it, bye.

You can have a message or a comment.

Web2py--------------use Web2py to write Django Examples--------build a poll application (3)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.