Get started with a little python:web.py frame every day

Source: Internet
Author: User

In the use of building a public platform, the use of web.py this convenient and simple framework, learning.

Framework Document:http://webpy.org/docs/0.3/tutorial.zh-cn write to the contents of the document once you get started, there's no problem.

To Run the program: CMD--Enter the path to the file--Enter a python file name to run

Problems encountered:

1. In the template file, the first line must start with the $def with (), or an error will be

$def with (name) $if name:    I just wanted to say <em>hello</em> to $name. $else:    <em>hello</em , world!

2. The Python statement in the template file HTML cannot be commented on, otherwise it will be an error. Others can be commented

Question 3: page jumps and redirects--web.seeother and Web.redirect

Links: http://doc.outofmemory.cn/python/webpy-cookbook/redirect-seeother.html

Class add:    def POST (self):        i=web.input ()        n=db.insert (' Todo ', title=i.title)        raise Web.seeother ('/') )

After the Post method receives a post and finishes processing, it sends a 303 message and a new URL to the browser. Next

The browser makes a GET request for the new URL, which completes the new jump.

Note: Web.seeother and Web.redirect do not support versions below 0.3.

Difference:

It seems to be possible to do the same thing with the Web.redirect method, but usually it is too friendly. Because Web.redirect is sending 301 messages-

This is a permanent redirect. Because most Web browsers cache new redirects, when we do that again, we automatically access

redirect The new URL. Many times, this is not the result we want. So when submitting the form, try to use Seeother. But in the following to

In this case, it is most appropriate to use redirect: We have changed the URL structure of the site, but still want to let the user bookmarks/favorites

The old URL does not expire. (Note: To understand the difference between seeother and redirect, it is best to look at the meanings of different message codes in the HTTP protocol.) )

Get started with a little python:web.py frame every day

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.