一、调整代码如下
import tornado.ioloop
import tornado.web
import tornado.options
from tornado.options import define, options
from handlers import Indexhandler, Pichandler
define('port', default='8888', help='Listening Port', type=int)
class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r'/', Indexhandler),
(r'/pic', Pichandler)
]
settings = dict(
debug=True,
static_path='static'
)
super().__init__(handlers, **settings)
if __name__ == '__main__':
tornado.options.parse_command_line()
app = Application()
app.listen(options.port)
print('server start on port {}'.format(options.port))
tornado.ioloop.IOLoop.current().start()
import tornado.web
HTML_TEMPLATE = """
<html>
<head><title>index page</title></head>
<body>
{}
</body>
</html>
"""
class Indexhandler(tornado.web.RequestHandler):
def get(self):
self.write(HTML_TEMPLATE.format('hello, world'))
class Pichandler(tornado.web.RequestHandler):
def get(self):
self.write(HTML_TEMPLATE.format('<img src="static/images/admin.png">'))
二、首页以及图片页面的展示
- 首页展示
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/fd2ef3e4862f5fa5e6101983a5aefeee.png)
- 图片页面展示(哈哈哈,来自章鱼哥的凝视,怕了怕了!!!)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e4e593166231ab45faf4b48d381661f0.png)
- 后台日志输出展示
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/0594cf360320b4398cfc340ebc90f8c4.png)