大家好,这里是 tornado 中的一个小应用程序,你可以告诉我如何从一个 html 导航到另一个 P.S 现在我收到错误 404 not found 我应该使用 appengine 还是需要任何其他东西 提前致谢
enter code here
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado.options import define, options
define("port", default=8888, help="run on the given port", type=int)
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render("template.html")
class indexhandler(tornado.web.RequestHandler):
def get(self):
self.render("index.html")
def main():
tornado.options.parse_command_line()
application = tornado.web.Application([
("/", MainHandler),
( "/index.html",indexhandler),
])
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(options.port)
tornado.ioloop.IOLoop.current().start()
if __name__ == "__main__":
main()
html页面1模板
<html>
<title>
basics
</title>
<head>
tornado
</head>
<body>
<h1> template</h1>
<a href="index.html">goes to index.html </a>
</body>
</html>
html -2 索引.hmtl
enter code here
<html>
<head> index
</head>
<body>
<h2>2nd page in this application</h2>
</body>
</html>
最佳答案
您发布的代码正在运行。在新的 virtualenv,最新的 torando 中,所有文件都在同一目录中:
kwarunek@home:/tmp$ virtualenv test
kwarunek@home:/tmp$ . test/bin/activate
(test)kwarunek@home:/tmp$ pip install tornado
(test)kwarunek@home:/tmp$ ls -l
-rw-rw-r-- 1 kwarunek kwarunek 89 01-06 11:54 index.html
-rw-rw-r-- 1 kwarunek kwarunek 768 01-06 11:53 server.py
-rw-rw-r-- 1 kwarunek kwarunek 143 01-06 11:54 template.html
drwxrwxr-x 5 kwarunek kwarunek 120 01-06 11:50 test/
(test)kwarunek@home:/tmp$ python server.py
[I 160106 11:55:59 web:1946] 200 GET / (127.0.0.1) 6.88ms
[W 160106 11:55:59 web:1946] 404 GET /favicon.ico (127.0.0.1) 1.73ms
[W 160106 11:55:59 web:1946] 404 GET /favicon.ico (127.0.0.1) 1.40ms
[I 160106 11:56:06 web:1946] 200 GET /index.html (127.0.0.1) 2.28ms
关于python - 如何使用 anchor 标记在 Tornado 中从一个 html 导航到另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34575989/