Skip to content

Commit ff7260e

Browse files
committed
Tornado 测试-模板使用
1 parent bfd0274 commit ff7260e

3 files changed

Lines changed: 60 additions & 0 deletions

File tree

File renamed without changes.

template/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head lang="en">
4+
<meta charset="UTF-8">
5+
<title>python web</title>
6+
</head>
7+
<body>
8+
Hello Python~~
9+
I will try my best to learn it !
10+
</body>
11+
</html>

web.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# encoding: utf-8
2+
__author__ = 'zhanghe'
3+
4+
import os
5+
import tornado.httpserver
6+
import tornado.web
7+
import tornado.ioloop
8+
import tornado.options
9+
# from handlers import *
10+
11+
from tornado.options import define, options
12+
define("port", default=8000, help="run on the given port", type=int)
13+
14+
15+
class IndexHandler(tornado.web.RequestHandler):
16+
def data_received(self, chunk):
17+
pass
18+
19+
def get(self):
20+
self.render('index.html')
21+
22+
def post(self):
23+
self.render('index.html')
24+
25+
26+
handlers = [
27+
(r'/', IndexHandler),
28+
# (r'/member', memberHandler),
29+
# (r'/chat/(\d+)', chatHandler),
30+
# (r'/register', registerHandler),
31+
# (r'/logout', logoutHandler),
32+
# (r'/post', postHandler),
33+
# (r'/user/(\w+)', userHandler),
34+
# (r'/blog/(\d+)', blogHandler),
35+
# (r'/comment', commentHandler),
36+
]
37+
settings = {
38+
'static_path': os.path.join(os.path.dirname(__file__), 'static'),
39+
'template_path': os.path.join(os.path.dirname(__file__), 'template'),
40+
}
41+
42+
43+
if __name__ == '__main__':
44+
tornado.options.parse_command_line()
45+
app = tornado.web.Application(handlers, **settings)
46+
http_server = tornado.httpserver.HTTPServer(app)
47+
http_server.listen(options.port)
48+
# app.listen(options.port) # 貌似这一句可以替代上面两句,待研究
49+
tornado.ioloop.IOLoop.instance().start()

0 commit comments

Comments
 (0)