python框架django-web层

1.demo

  命令行:django-admin startproject HelloWorld

  命令执行成功后会根据模版生产一个django项目

  然后通过 命令:python3 manage.py runserver 0.0.0.0:8000,启动服务

服务架构

2.服务启动

执行命令后通过一系列的初始化工作,会进入一下代码

def run(addr, port, wsgi_handler, ipv6=False, threading=False, server_cls=WSGIServer):
    server_address = (addr, port)
    if threading:
        httpd_cls = type('WSGIServer', (socketserver.ThreadingMixIn, server_cls), {})
    else:
        httpd_cls = server_cls
    httpd = httpd_cls(server_address, WSGIRequestHandler, ipv6=ipv6)
    if threading:
        # ThreadingMixIn.daemon_threads indicates how threads will behave on an
        # abrupt shutdown; like quitting the server by the user or restarting
        # by the auto-reloader. True means the server will not wait for thread
        # termination before it quits. This will make auto-reloader faster
        # and will prevent the need to kill the server manually if a thread
        # isn't terminating correctly.
        httpd.daemon_threads = True
    httpd.set_app(wsgi_handler)
    httpd.serve_forever()

启动了WSGIServer,server中通过实现自己handler,来完成自己认为,在handler中先调用应用发现函数找到对应的应用,aplication在接到上一层的请求后通过执行一些列的middleware来完成整个请求。

猜你喜欢

转载自www.cnblogs.com/yangyang12138/p/10772092.html
今日推荐