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()
  • 相关阅读:
    hdu 1255 矩形覆盖面积(面积交)
    hdu 3642 覆盖3次以上体积
    hdu 3255 体积并
    hdu 3265 矩形剪块面积并
    HDU 3397 区间覆盖,颠倒,合并(好题)
    ACM-线段树扫描线总结
    POJ 3667 线段树区间合并
    数组排序----Demo
    Spring MVC配置详解(3)
    生产者消费者模式--
  • 原文地址:https://www.cnblogs.com/tangpg/p/9469244.html
Copyright © 2011-2022 走看看