With Python for web development There are many frameworks to choose from, such as the most famous Django,tornado, and in addition to these frameworks, there is a lightweight framework to use is very convenient and handy, is web.py. It was created by a hacker, but unfortunately the founder committed suicide in 2013. It is said that it is now maintained and updated by another person. Find out how to build the web.py development environment under Windows now.
I. Installation web.py
Download the web.py installation package on the https://github.com/webpy/webpy. Note that GitHub has requirements for the browser version, such as not supporting IE9 below.
Download the appropriate version yourself as needed.
After downloading, unzip, open CMD,CD to unzip the directory, enter
Python setup.py Install
The installation is complete. (If you have to install Python,python3 versions below)
Two. Test the program.
Create a hello.py file
123456789101112 |
import web urls
= (
‘/hello‘
,
‘hello‘
,
)
class hello(
object
):
def GET(
self
):
return ‘hello world‘
if __name__
=
= "__main__"
:
app
= web.application(urls,
globals
())
app.run()
|
URLs are URL mapping rules (similar to mappings in Servlets), and class Hello is a link request response.
Then run the file under the command line:
If you want to stop the program CTRL + C, you can exit. The default program runs on port 8080, and then in the browser: Http://127.0.0.1:8080/hello, you can see the results:
The program runs on port 8080 by default, and if the 8080 port is occupied by another program, the web.py program fails, such as a sockets.error error, which requires the port to be changed:
Note web.py does not have the ability to deploy Web sites, so for web.py programs you can only access them locally, and if you want to deploy it you must use Apache or Nginx.
How to quickly build a web.py development framework under Windows