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 .)