• 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()
  • 相关阅读:
    PHPStorm下XDebug配置
    HDU 4633 Who's Aunt Zhang (Polya定理+快速幂)
    VC++深入详解-第五章学习心得
    nginx access log logrotate配置
    判断变量是否存在(python)
    一步一步学android之布局管理器——LinearLayout
    向前辈致敬 strspn
    poj 1087 (最大流)
    cocos2d-x Touch 事件应用的一个例子
    [置顶] C#扩展方法 扩你所需
  • 原文地址:https://www.cnblogs.com/tangpg/p/9469244.html
Copyright © 2020-2023  润新知