-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
41 lines (36 loc) · 1.47 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#! /usr/bin/python3
# -*- coding:utf-8 -*-
# Author: huangjian
# Email: huangjian1820@gmail.com
# Version: 1.0
import tornado.ioloop
import tornado.web
import os
from tornado.options import define, options
from common.url_router import include, url_wrapper
from models.user import initdb
from sqlalchemy.orm import scoped_session, sessionmaker
from conf.base import engine
class Application(tornado.web.Application):
def __init__(self):
initdb()
handlers = url_wrapper([
(r"/", include('views.home.home_urls')),
(r"/users/", include('views.users.users_urls')),
(r"/upload/", include('views.upload.upload_urls'))
])
# 定义 Tornado 服务器的配置项,如 static/templates 目录位置,debug 级别等
settings = dict(
debug=True,
static_path=os.path.join(os.path.dirname(__file__), "static"),
template_path=os.path.join(os.path.dirname(__file__), "templates")
)
tornado.web.Application.__init__(self, handlers, **settings)
self.db = scoped_session(sessionmaker(bind=engine,
autocommit=False, autoflush=True,
expire_on_commit=False))
if __name__ == '__main__':
print("Tornado server is running at http://127.0.0.1:8000\r")
tornado.options.parse_command_line()
Application().listen(8000, xheaders=True)
tornado.ioloop.IOLoop.instance().start()