Python note (8): web development and python note web development
# In Windows, two more things should be set for Unix systems.
(1)Design web applications with MVC
Model-view-controlle)
Model: code for storing web Application Data
View: Format and display the code on the web Application User Interface
Controller: code that binds web applications and provides business logic
(2)Recommended folder structure
WebAPP: custom
Cgi-bin: stores code
Data: stores data.
Images: stores images
Templates: storage Template
(3) CGI allows web servers to run programs
Create a python file (the following code is required to build a web server using python)
FromHttp. serverImportHTTPServer, CGIHTTPRequestHandler
Port = 8099
Httpd = HTTPServer (('', Port), CGIHTTPRequestHandler)
Print ('The port number is'+ Str (httpd. server_port ))
Httpd. serve_forever ()
(4)Run
Start. py is the file used to store the above Code.
Access:
(5)Source code
If you are interested, you can download it to the online storage.
Https://pan.baidu.com/s/1diVNuY password: xsaz
Then, (1) create a project using pycharm (with your own IDE.
(2) copy the following files to the project.
(3) Right-click cgi-bin and set the following. (If you do not set direct import to your own module, an error will be reported.) In addition, generate_list.py and yate. change the absolute path in the code in the two files of py to your own path (I originally wanted to use the relative path, but I don't know why the IDE can run it when using the relative path, when running on the web server, an error is reported)
(4) Then you can run and access http: // localhost: 8099 (if the port number is changed, use the modified one)