Web2py--------------use Web2py to write Django examples--------build a voting app

Source: Internet
Author: User
Tags web2py

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

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.