来自Python的龙卷风重定向问题

时间:2018-10-12 05:18:20

标签: javascript python get tornado

我尝试过早问这个问题,但没有得到回应。现在发布显示此问题的最小代码。我正在使用Python 3.6.3和新版的Tornado(5.1.1)。首先是index.html。加载时,我正在/ login上执行get请求,该请求由python龙卷风服务器处理(请参见html代码之后)。

<!DOCTYPE html>
<html>

<script src="https://d3js.org/d3.v3.js"></script>
<script>


    function login(){
      var params = window.location.search;
      d3.xhr("http://localhost:8000/login")
        .get(function(err, data){
            console.log(data);
        });
    }

</script>
<body onload="login()">
<p id="params"></p>
<span onclick="login()">Click Here to ReadCode</span> 
</body>
</html>

服务器代码具有以下内容:

import tornado.ioloop
import tornado.web
import os
R_URL='http://example.com'
class MainHandler(tornado.web.RequestHandler):
    def set_default_headers(self):
       print("setting headers!!!")
       self.set_header("access-control-allow-origin", "*")
       self.set_header('Access-Control-Allow-Methods', 'GET, PUT, DELETE, OPTIONS')

       self.set_header("Access-Control-Allow-Credentials", "true")
       self.set_header("Access-Control-Allow-Headers",
                    "Authorization, Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, X-Requested-By, If-Modified-Since, X-File-Name, Cache-Control")

    def get(self):
       print("GET: MainHandler::localhost")
       self.redirect(R_URL)

def make_app():
   root = os.path.dirname(__file__)
   print("root", root)
   application = tornado.web.Application([
    (r"/login", MainHandler),
    (r"/(.*)", tornado.web.StaticFileHandler, {"path": root, "default_filename": "index.html"}),
])
   return application

if __name__ == "__main__":
app = make_app()
app.listen(8000)
print("Listening on port 8000")
tornado.ioloop.IOLoop.current().start()

执行此操作时,我在浏览器中不断收到此错误以进行重定向,但不确定如何删除该错误。我尝试了我在Google上看到的所有建议。

0 个答案:

没有答案