Home > Backend Development > Python Tutorial > A preliminary exploration of web.py - the first page hello word

A preliminary exploration of web.py - the first page hello word

高洛峰
Release: 2016-10-17 14:43:19
Original
1435 people have browsed it

In the previous article, web.py installation details, I shared with you the installation of web.py. This article will talk about the first page of web.py, hello world.
If you have a Python foundation, getting started with web.py is very simple. . Writing web programs is also very smooth, which is one of the advantages of web.py.

Hello world program is very simple, we can directly open the Python interactive interpreter. The command is as follows:

#Enter python command line mode

shell# python

#Introduce the web module

>>>import web

#The function of this line is to declare the url of the website. The first parameter is a regular expression used to match the URL, and the second parameter is the class that our URL needs to process.

>>>urls=('/','index')

#Use this url to create a program:

>>>app=web.application(urls, globals())

#The next step is to define the index class just mentioned:

>>>class index:

                    def GET(self):                                                                                                                     .

Pay attention here GET is defined to request a web page, and the Html code returned is the content of the displayed web page. Another important function is POST, which is used to submit the form. In this simple program, there is no need to interact with the user, so only the GET function is defined.

GET and POST are the two most basic forms of web page interaction. It is commonly used in form forms and Ajax. Students who are not familiar with this aspect can google it.

#Finally let the program run

>>>app.run()

What we will see is http://0.0.0.0:8080/

where 8080 represents The port number.

Enter the above address directly into the browser and you will see the Hello World page!

If you write it directly as a script, just execute Python filename.py.

It’s very simple

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template