The first page helloword of web. py

Source: Internet
Author: User
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

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.