Web2py -------------- example of using web2py to write django, web2pydjango

Source: Internet
Author: User
Tags web2py

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

 

Related Article

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.