how to navigate from one html to other in tornado using anchor tag

北城以北 提交于 2019-12-23 23:29:27

问题


Hi all here is a small application in tornado can any off u please tell me how to navigate from one html to other P.S Now i am getting a error 404 not found should i be using appengine or any other thing is required thanks in advance

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 page 1 template

<html>
<title>
basics
</title>
<head>
tornado
</head>
<body>
<h1> template</h1>
 <a href="index.html">goes to index.html </a> 
</body>
</html>

html -2 index.hmtl

enter code here
<html>
<head> index
</head>
<body>
<h2>2nd page in this application</h2>
</body>
</html>

回答1:


Code you post is working. In new virtualenv, newest torando, all files in the same directory:

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


来源:https://stackoverflow.com/questions/34575989/how-to-navigate-from-one-html-to-other-in-tornado-using-anchor-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!