Home >Backend Development >Python Tutorial >A preliminary exploration of web.py - the first page hello word
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