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()

 

posted on 2018-08-13 16:48 .Tang 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/tangpg/p/9469244.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值