龙卷风重定向到带有参数的页面

用户名

我正在self.render渲染一个html模板,它依赖于通过ajax从客户端从客户端接收的信息,def post()如下所示:

class aHandler(BaseHandler):
    @tornado.web.authenticated
    def post(self):
        taskComp = json.loads(self.request.body)   
        if taskComp['type'] == 'edit':
            if taskComp['taskType'] == 'task':
                self.render(
                    "tasks.html",         
                    user=self.current_user,
                    timestamp='',
                    projects='',
                    type='',
                    taskCount='',
                    resName='')

但是,这不会将用户重定向到html页面'tasks.html'。

但是我在控制台中看到一个状态:

[I 141215 16:00:55 web:1811] 200 GET /tasks (127.0.0.1)

其中“ / tasks”是task.html的别名

为什么不将其重定向?

还是如何使用从ajax接收的数据以及上面self.render请求中提供的所有参数将其重定向到task.html页面

杰西·杰鲁·戴维斯(A. ​​Jesse Jiryu Davis)

“渲染”从不将访问者的浏览器重定向到其他URL。它向浏览器显示您呈现的页面内容,在本例中为“ tasks.html”模板。

重定向浏览器:

@tornado.web.authenticated
    def post(self):
        self.redirect('/tasks')
        return

重定向文档更多信息

要使用AJAX响应进行重定向,请尝试将目标位置从Python发送到Javascript:

class aHandler(BaseHandler):
    @tornado.web.authenticated
    def post(self):
        self.write(json.dumps(dict(
            location='/tasks',
            user=self.current_user,
            timestamp='',
            projects='',
            type='',
            taskCount='',
            resName='')))

然后在Javascript中的AJAX响应处理程序中:

$.ajax({
  url: "url",
}).done(function(data) {
  var url = data.location + '?user=' + data.user + '&timestamp=' + data.timestamp; // etc.
  window.location.replace("http://stackoverflow.com");
});

有关URL编码的更多信息,请参见此答案

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章