In the previous article about web. py, helloword, the first page of web. py, I explained how to install web. py. in this article, let's take a look at hello world, the first page of web. py.
If you have Python basics, it is very easy to get started with web. py. Writing web programs is also very smooth, which is also an advantage of web. py.
The Hello world program is very simple. we can directly open the Python interactive interpreter. The command is as follows:
# Entering the python command line mode
Shell # python
# Introduce the web module
>>> Import web
# This line declares the website url. The first parameter is a regular expression used to match the url, and the second parameter is the class to be processed by the url.
>>> Urls = ('/', 'index ')
# Use this url to create a program:
>>> App = web. application (urls, globals ())
# Next, define the index class just mentioned:
>>> Class index:
Def GET (self ):
Return 'Hello World! '
Note that GET is defined to request a webpage. the Html code returned at the end is the content of the webpage. Another important function is POST, which is used to submit forms. in this simple program, it does not need to interact with users,
Therefore, only the GET function is defined.
GET and POST are two basic forms of webpage interaction. It is often used in form and Ajax. if you are not familiar with this, you can google it.
# Finally let the program run.
>>> App. run ()
We will see http: // 0.0.0.0: 8080/
8080 indicates the port number.
Enter the preceding address in the browser to view the Hello World page!
If you directly write a script, execute Python filename. py.
Very simple