zoukankan      html  css  js  c++  java
  • tornado-5.1版本

    server.py

    python server.py执行

    import tornado.ioloop
    import tornado.options
    import tornado.web
    from tornado.options import define, options
    
    from handlers.main import main_handler
    from handlers.auth import auth_handler
    
    
    define('port', default=8000, type=int, help='Listening port')
    ##
    
    class AppConfig(tornado.web.Application):
        """ 继承了Application重写init,再将重写的参数通过super传给Application """
        def __init__(self):
            handlers = [
                (r'/', main_handler.MainHandler),
                (r'/post/(?P<id>[0-9]{1,})', main_handler.ALoneHandler),
            ]
            settings = dict(
                debug=True,
                template_path='templates',
                static_path='static',
                login_url='/login',
                cookie_secret='fagawg',
                pycket={
                    'engine': 'redis',
                    'storage': {
                        'host': 'localhost',
                        'port': 6379,
                        'db_sessions': 2,
                        # 'password': '',
                        'db_notifications': 11,
                        'max_connections': 2 ** 31,
                    },
                    'cookies': {
                        'expires_days': 30,
                        'max_age': 5000
                    }
                },
            )
            super(AppConfig, self).__init__(handlers=handlers, **settings)
    
    
    application = AppConfig()
    ### or
    '''
    handlers = [
        (r'/', main_handler.MainHandler),
    ]
    settings = dict(
        debug=True,
        template_path='templates',
        static_path='static'
    )
    application=tornado.web.Application(handlers=handlers, **settings)
    '''
    
    if __name__ == '__main__':
        options.parse_command_line()
        application.listen(options.port)
        print('Sever start on port {}...'.format(options.port))
        tornado.ioloop.IOLoop.current().start()
  • 相关阅读:
    CentOS7-Docker容器入门
    CentOS7-Docker 配置国内镜像源
    CentOS7 下 yum 安装 Docker CE
    VirtualBox 配置 CentOS7网卡信息
    MySQL忘记密码后重置密码(Mac )
    三栏布局的n种实现
    Seata Server环境搭建
    Nacos安装
    排查系统端口被占用
    Netty网络高性能核心原理
  • 原文地址:https://www.cnblogs.com/tangpg/p/9469244.html
Copyright © 2011-2022 走看看