在Tornado上将变量从一个网站传递到另一个网站

时间:2015-08-24 13:54:31

标签: python localhost tornado argument-passing

我想使用Tornado将对象从一个网页('localhost / form')传递到另一个重定向网页('localhost / redirect')。 我的代码片段看起来像这样..

class FormHandler (BaseHandler):
def get(self):
        redirect_page='localhost/redirect'
        some_variable='a variable that can only be generated in FormHandler'
        self.write('<button id="Redirect" type="button">Redirect</button><br><script> document.getElementById("Redirect").onclick = function () {location.href ="'redirect_page'";};</script>')


class RedirectHander (BaseHandler):
        self.write('The variable passed was'+some_variable)

def make_app():
return Application(
    [
        url('/', BaseHandler, { "var":"nothing" }, name="root"), # this is for the root! :)
        url('/form', FormHandler, { "var":"initialize this!" }, name = "forlorn"),
        url('/redirect', RedirectHandler, { "var":"initialize this!" }, name = "forlorn"),
    ],
    # settings:
    debug = True,
)

0 个答案:

没有答案