我想做一个网页。但我无法加载 html 中的图像文件。我不知道为什么会出现这种情况。我附上了 HTML 代码、python Tornado 代码。 你能帮我吗?
HTML 文件
<!DOCTYPE html>
<html>
<body>
<p>The GIF standard allows moving images.</p>
<img src="programming.gif" alt="Computer man" style="width:148px;hei ght:148px;">
</body>
</html>
Python- Tornado 文件
import tornado.web
import tornado.ioloop
import tornado.httpserver
class Handler(tornado.web.RequestHandler):
def get(self):
self.render("html_image_05.html")
application = tornado.web.Application([
(r"/",Handler)
])
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(80)
tornado.ioloop.IOLoop.instance().start()
这是我执行此代码时的消息代码。
WARNING:tornado.access:404 GET /eh5v.files/html5video/test.jpg (127.0.0.1) 0.56ms
WARNING:tornado.access:404 GET /eh5v.files/html5video/html5ext.js (127.0.0.1) 0.41ms
WARNING:tornado.access:404 GET /eh5v.files/html5video/test.m4v (127.0.0.1) 0.48ms
WARNING:tornado.access:404 GET /eh5v.files/html5video/test.jpg (127.0.0.1) 0.34ms
WARNING:tornado.access:404 GET /eh5v.files/html5video/test.webm (127.0.0.1) 0.36ms
最佳答案
我已经解决了这个问题。 就是这样。
Python 文件代码(已修复)
import tornado.web
import tornado.ioloop
import tornado.httpserver
class Handler(tornado.web.RequestHandler):
def get(self):
self.render("html_image_05.html")
application = tornado.web.Application([
(r"/",Handler),
(r"/(programming.gif)", tornado.web.StaticFileHandler, {'path':'./'}) <--Add!
])
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(80)
tornado.ioloop.IOLoop.instance().start()
这是关于将图像与 html 和 python 文件连接的解决方案。
关于python - 如何在python Tornado 上加载html图像文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32288515/