Web Framework Introduction

Source: Internet
Author: User

First, the nature of web framework

    • All Web applications are essentially sockets, and the user's browser is actually a socket client.
    • Common web Frameworks in Python are:
      • Django
      • Flask
      • web.py
    • WSGI (Web server Gateway Interface) defines the interface format between Web apps and Web servers that are programmed with Python, enabling decoupling between the server and the client.
    • The standalone WSGI server provided by the Pytho Standard library is known as wsgired.

Ii. using wsgrired to customize the web framework

#!/usr/local/bin/python3#-*-coding:utf-8-*-#Author:felix Song; Environment:pycharm 5.0.3 (python3.6)#develop a web framework of your own using the Python standard library fromWsgiref.simple_serverImportMake_server#Second Step transformation, get the content in ConfImportConf_urldefRunserver (environ,start_response): Start_response ('OK',[('Content-type','text/html')])    #The first step, get the user url,debug mode, in Start_response plus breakpoint, then browser access in variables under the Environ findUserurl = environ['Path_info']    Print(userurl) urlpatterns= Conf_url.routes ()#Third Step Transformation    #Second Step transformationFunc =None#For item in Conf_url.url: #第三步注释掉     forIteminchUrlpatterns:#Third Step Transformation        ifItem[0] = =Userurl:func= Item[1]             Break    iffunc:returnfunc ()Else:        return[Bytes ('', encoding='Utf-8')]    " "#第二步, different values are returned depending on the URL input, but if the page is much more laborious with the if else ... Under renovation, create a new conf.py inside define all the URL models if Userurl = = '/index/': return [bytes (' " "if __name__=='__main__': httpd= Make_server ("', 8000, Runserver)Print('serving HTTP on port 8000 ...') Httpd.serve_forever ()
Server
#!/usr/local/bin/python3#-*-coding:utf-8-*-#Author:felix Song; Environment:pycharm 5.0.3 (python3.6)defindex ():return[Bytes ('', encoding='Utf-8')]    #return [b ' deflogin ():return[Bytes ('', encoding='Utf-8')]#Third step transformation, routing systemdefroutes (): Urlpatterns= (('/index', index), ('/index', index), ('/index', index)) returnUrlpatterns##第二步改造, Web page comparison#URL = (#('/index ', index),#('/index ', index),#('/index ', index),# )
Conf_url

III. MVC Framework (collation of code)

Model package: Working with databases

View package: Storing HTML files

Login.html:

Controller package: Business logic processing

account.py: Account-related controls are here

admin.py: Background Management

IV. MTV Framework (Classification of code)

Model Package: Operations on the database

Template package: Storing HTML files

View Package: Business logic

Reference:

Http://www.cnblogs.com/wupeiqi/articles/4491246.html

Http://www.cnblogs.com/wupeiqi/articles/5237672.html

Web Framework Introduction

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.