Python notes (eight): Web development

Source: Internet
Author: User

#本文是在Windows环境下, a UNIX system should have 2 more things to set up.

(i) designing Web applications with MVC

Follow model-View-controller (Model-view-controlle)

Model: Code that stores web app data

View: Formatting and displaying code for the Web App user interface

Controllers: Code that binds web apps together and provides business logic

(ii) Recommended folder structure

WebAPP: Custom

Cgi-bin: Store Code

Data: Storage

Images: Storing pictures

Templates: Storing templates

(iii) CGI let the Web server run the program

Create a Python file (build a Web server in Python with the following code)

from Http.server import Httpserver,cgihttprequesthandler

Port = 8099
httpd = Httpserver (("', Port), Cgihttprequesthandler)
Print (' port number is '+ str (httpd.server_port))
Httpd.serve_forever ()

(iv) Run

start.py is the file I used to store the code above.

Access:

(v) Source Code

Interested in can be downloaded to the network disk reference

Https://pan.baidu.com/s/1diVNuY Password: xsaz

Then, (1) Use Pycharm (with your own IDE) to create a project.

(2) Copy the following files to the project.

(3) Right click on Cgi-bin, set the following. (Do not set the direct import of their own module will be error) and then put the inside generate_list.py, Yate.py these 2 files in the code of the absolute path to your own path (originally want to use a relative path, but do not know why the use of relative path when the IDE can be run, the Web server running error)

(4) Then you can run access to the http://localhost:8099 (if you change the port number with the modified)

Python notes (eight): Web development

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.