A little python every day: getting started with the web. py framework, pythonweb. py framework

Source: Internet
Author: User

A little python every day: getting started with the web. py framework, pythonweb. py framework

When building a public platform, you can use web. py, a convenient and simple framework.

Framework document:Http://webpy.org/docs/0.3/tutorial.zh-cn according to the content of the document to write the program entry is no problem

Run the program:Cmd -- enter the file path -- enter the python file name to run

Problems:

Problem 1. In the template file, the first line must start with $ def with (); otherwise, an error is reported.

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

Problem 2. the python statement in the template file html cannot be commented out; otherwise, an error is reported. Other annotations

Problem 3. webpage redirection-web. seeother and web. redirect

Link: 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 completes processing, it will send a 303 message and a new URL to the browser. Next,

The browser sends a GET request to the new URL to complete the new jump.

Note: web. seeother and web. redirect versions earlier than 0.3 are not supported.

Differences:

The same can be done using the web. redirect method, but this is usually too friendly. Because web. redirect sends a 301 message-

This is a permanent redirect. Because most Web browsers cache new redirects, when we perform this operation again, it will automatically access

The new URL to be redirected. Most of the time, this is not what we want. Therefore, when submitting a form, try to use seeother. However

In this case, redirect is the most appropriate: we have changed the website URL structure, but still want to make the user bookmarks/favorites in

The old website address is not invalid. (Note: to understand the difference between seeother and redirect, it is best to take a look at the meaning of different message codes in the http protocol .)

 

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.