Python note (8): web development and python note web development

Source: Internet
Author: User

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)

 

 

 

 

Related Article

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.