python - 如何使用 anchor 标记在 Tornado 中从一个 html 导航到另一个

标签 python html tornado jinja2

大家好,这里是 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/

相关文章:

python - networkx 中图形的遍历级别顺序

python - 在子类中添加

javascript - html-css 自动 slider 按钮不起作用

python - 是否有 R 的 nrd0 的 scipy/numpy 替代品?

python - 使用参数从 TCL 脚本调用 Python 函数

python - 为什么较长的 HTTP 往返时间会使我的 Tornado AsyncHttpClient 停滞不前?

python - Tornado:异步端点

php - 使用 PHP 和 Tornado

html - 具有相同宽度的子跨度

javascript - 单选按钮值未显示