1 Star 2 Fork 1

孔令溪/tornado-tutorial

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
manage.py 2.10 KB
一键复制 编辑 原始数据 按行查看 历史
LINSHIMUYE\08780 提交于 2019-09-20 11:37 . 修改readme.md
#!/usr/bin/env python
# encoding: utf-8
"""
@version: v1.0
@author: konglingxi
@contact: 1319328276@qq.com
@software: PyCharm
@file: manage.py
@time: 2019/9/18 22:30
"""
from __future__ import unicode_literals
import os
import tornado.web
import tornado.ioloop
from tornado.options import parse_command_line, define, options
from apps.chat_views import ChatHandler, NewChatHandler
from apps.user_views import RegisterHandler, LoginHandler
from apps.views import IndexHandler, CreateDbHandler, DropDbHandler, TestHandler
from utils.chat_websocket import ChatWebSocket
define('port', default=80, type=int, help='host port')
class Application(tornado.web.Application):
def __init__(self):
self.chatWebSocket = ChatWebSocket()
if not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')):
os.makedirs(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates'))
if not os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static')):
os.makedirs(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static'))
handlers = [
(r'/$', IndexHandler),
(r'/test/', TestHandler),
(r'/create-db/', CreateDbHandler),
(r'/drop-db/', DropDbHandler),
(r'/register/', RegisterHandler),
(r'/login/', LoginHandler),
(r'/chat/', ChatHandler),
(r'/new-chat/', NewChatHandler),
]
settings = {
'template_path': os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates'),
'static_path': os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static'),
}
tornado.web.Application.__init__(self, handlers, **settings)
if __name__ == '__main__':
address = '127.0.0.1'
# 读取命令行参数
parse_command_line()
# 实例化应用
app = Application()
# 监听端口
app.listen(options.port, address=address)
# 启动
print('Starting development server at http://{}:{}/'.format(address, options.port))
tornado.ioloop.IOLoop.current().start()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/konglingxi/tornado-tutorial.git
git@gitee.com:konglingxi/tornado-tutorial.git
konglingxi
tornado-tutorial
tornado-tutorial
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385